Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a windows application and I want to create a click once app.After creating clickonce app from visual studio when I deploy the file on client machine it throws error when trying to access database.I have included database file within the clickonce app.The database file is stored on client pc on location :
C:\Users\Admin\AppData\Local\Apps\2.0\Data\8Z14E1HB.329\P54O9PWP.VCY\ nain..tion_b5deb07cfd237918_0001.0000_ce0d12c892dd7f73\Data\Database1.mdf

What connection string should I mentioned in my project that when code is published it should access the location the database is stored on client machine.
The current connectionstring is :

This connectionstring works fine when I run the code from visual studio but wont work on client side.

What I have tried:

Tried to change connection string but to no avail.If keep same connectionstring throws error 'A network related or instance specific error while establishing connection to Sql Server error-40 Could not open connection to Sql Server '
Posted
Updated 28-Sep-16 3:40am
Comments
[no name] 28-Sep-16 8:58am    
Well if your connection string is completely empty like you have shown us, then it couldn't possibly work.

1 solution

That's not how SQL Server works. You don't copy the .mdf file to the client computer; you attach it to an existing instance of SQL Server, and have the client connect to that instance.

If you're using the AttachDBFileName option, the user will need to have a copy of SQL Server Express installed on their computer. You will also find that the database will not be shared between different instances of your application, or between different users or different computers.

Bad habits : Using AttachDBFileName - SQL SentrySQL Sentry Team Blog[^]

Also note that this feature will be removed in a future version:

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.


If you want a simple file-based database, you could use LocalDB[^], but that still needs to be installed. Alternatively, you could use SQL CE, but that has far fewer features.

SQL Express v LocalDB v SQL Compact Edition – Jerry Nixon[^]
 
Share this answer
 
Comments
Karthik_Mahalingam 29-Sep-16 1:08am    
5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900