Connection string
-
Friday, September 21, 2012 12:30 PM
Hi Guys,
I am writing an executable file in c# that will be deployed and run on different computers and needs to establish a connection to an sql database... how would I be able to do this?
I tried localhost but it does not connect. Please help.
Regards,
Camren
Camren Chetty
All Replies
-
Friday, September 21, 2012 12:51 PM
I tried localhost but it does not connect. Please help.
Hello Camren,
In the connection string you have to use the name of the machine where the SQL Server is running, of course. "Localhost" works only, when you try to connect to a local server, but not for remote server.
Olaf Helper
Blog Xing- Marked As Answer by Iric WenModerator Tuesday, October 02, 2012 8:12 AM
-
Friday, September 21, 2012 1:38 PMBut this needs to be an executable application that can run on any machine
Camren Chetty
-
Friday, September 21, 2012 7:44 PM
You have 2 choices :-
First : Fix the SQL server to which you want to connect from all application servers. Ensure to have network access between SQL Server & Applciation box. Hardcode user name, password & server nam ein your applcaition.
Second : Give configuration feature to your applciation, so that you can enter server name, user name & password before executing.
Regards,
Rohit Garg
(My Blog)
This posting is provided with no warranties and confers no rights.
Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread.- Marked As Answer by Iric WenModerator Tuesday, October 02, 2012 8:12 AM
-
Friday, September 21, 2012 8:22 PM
Hi Camren,
like Olaf said localhost is only for local connections to a database. From Rohit suggestions I would choose the first one. In your application you just have to include the right connection string to operate against your database. How an appropriate connection string looks like can be found on the following site - http://www.connectionstrings.com/
Best Regards. When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer. This helps us build a healthy and positive community.
- Marked As Answer by Iric WenModerator Tuesday, October 02, 2012 8:12 AM
-
Tuesday, September 25, 2012 10:14 PMModerator
Hello,
I would prefer to use a connection form than to put the connection string in the app.config or similar for at least 2 reasons :
- for security : the connection string is too easy to see and to modify. It is possible to encrypt the connection string stored in the app.config , but it is more complex to code.
- for easiness : it makes easier every move of the SQL Server instance from a computer to another one
Have a nice day
PS : Please, could you tell us whether you install your application on several computers with only one SQL Server instance and database or on each computer where the application is installed you have a separated (stand-alone) SQL Server ?
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
- Marked As Answer by Iric WenModerator Tuesday, October 02, 2012 8:13 AM

