Reputation: 1
I am having errors running my windows form application on the client computer. I have a database called LoginData.mdf which is a LocalDB, and i want to attach it to my published project. Here is my connection string
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Globals.login_DB_path + @"\" + Globals.login_Db_name + ";Integrated Security=True;Connect Timeout=30;");
where
public static class Globals
{
public static String login_DB_path = "|DataDirectory|";
//Path.GetFullPath(Environment.CurrentDirectory);
public static String login_Db_name = "Logindata.mdf";
}
I have already looked at this thread : publish a project with local database
but when i install the entire folder in my client computer and set it up, after I open my click once application from the created an app folder which looks like:
-Application Files
Bombardier Manager_1_0_0_1
Bombardier Manager.exe.config.deploy
Bombardier Manager: click once app
.... the .mdf and log.ldf are also her
-Bombardier Manager: click once app
-setup
I setup the file on the client computer intially and it downloaded the SQL Server Express Local DB and the .NET framework on the client computer as i put t hem as prerequisites, I also added the Data Files in the Application files section.
After the setup I double clicked the click once app in the main folder. It ran but gave me the error that it couldn't access the sql database; that is already included in the application. Also then later when I tried to run the click once app from the Bombardier Manager_1_0_0_1 folder it said that i couldn't run it from there since it had been installed from somewhere else. I dont understand what to do since I followed all the steps in the given link above but it still gives me the same errors as before that the SQLDatabase is not accessible.
Any help would be appreciated.
Upvotes: 0
Views: 4624
Reputation: 89
I had the same struggle as HelpSeekerandGiver. This is how I solved my problem (Microsoft didn't make it easy):
Setup the localDB by right clicking the project file in solution explorer, choose Add -> new items->visual C# items->Data->Service-based Database
, find instructions to setup your data tables.
Verify a .mdf file is created in the same folder as your executable for each database table.
Check to include the .mdf files as prerequisites in your publish setting page.
I used SQL server express 2017 in my development environment. So I have to install the 2017 version on my client system as well. However, DON'T install the server, install the localDB instead. It is tricky. Follow instructions on this page.
Finally, after you go through ClickOnce to install on your client computer, you need to start the executable in the installed directory instead of the shortcut on the desktop. The directory is pretty deep, something link c:->users->your folder->AppData(this is a hidden folder, you need to change explorer setting to show it)->local->Apps->2.0->....
Upvotes: 0
Reputation: 31
I don't know if this will help, but have you tried to have you .mdf, for example, in the same directory as the program. Then just make the connection string from the .config file in Settings Like this
This worked for me, making conn simple with LocalDB.
Upvotes: 0
Reputation:
Did you include the database as "Application File"? If not do the following (at least this is how I am doing it):
Project -> Properties -> Publish -> Application Files
Upvotes: 0