Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing one windows application in c# and using this connection string while creating set up project.


Data Source=.\\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\\HM.mdf;Integrated Security=True;user instance=true

set up file runs on my pc successfully but getting error of sql server not found on other pc
Posted
Updated 17-Jun-11 1:20am
v3
Comments
Sergey Alexandrovich Kryukov 17-Jun-11 16:25pm    
Yes of course. Why this is a problem?
--SA

A few of ideas:

First the connection you have specified is pointing at the local machine: Data Source=.\\SQLEXPRESS , so the machine the application runs on will also need a SQLExpress server running as "SQLEXPRESS". This could be the cause of your problem. (It is difficult to tell as so many factors come into play). To form a more portible connection string this site may be of help[^]. You should also check the mdf file is deployed on installation. This is a slightly unusual setup as databases are typically deployed to a common server rather than locally.

The second thing is that it is more usual to store your config in the app.config (or web.cofig) file, it means you can change the database connection without deploying code for one thing. Instructions for doing that can be found here[^]. You can change the config according to debug and release builds, but how you do this depends on your application type and .net framework version. Finally, if you are worried about users seeing the connection string it is possible to encrypt it, this does take a little effort. You can see the basics here[^] but the instructions given may not fit your deployment scenario (they work on a web server for example, but the key must be accessible to the account running the application). It is possible to write your own ProtectedConfiguationProvider if necessary.
 
Share this answer
 
Comments
mayur csharp G 17-Jun-11 8:06am    
thanks for your comment i have taken sqlexpress in prerequistics of set up project and other necessary files.
It solved my problem
Keith Barrow 17-Jun-11 8:07am    
Glad to be of help!
mayur csharp G 17-Jun-11 8:20am    
can you please suggest one more thing?. whenever i am deploying my project on different PC its pixels are getting here and there, what might be best solution for this
Sergey Alexandrovich Kryukov 17-Jun-11 16:25pm    
Right, my 5.
--SA
The other PC might not have SQLEXPRESS installed on it.
You specified .\SQLEXPRESS, which means SQLEXPRESS of the local machine is being used.
 
Share this answer
 

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