Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Every one

I have a problem that i built a project in windows form c#
which is dealing with stroing and retriving of data in sql server 2008 database
but , for building process i coded the server name of my machine now i have to install it in client machine how can i change this server name with client server name other wise it will shows a server not found error.
I need more suggestions


Thank you .
Posted

You should not hard code server name and connection string.Store them in app.config instead.So that at l tare date, if you want to change connection string you only have to make change in app.config and not in your code.
add section like below in you app.config
XML
<appSettings>
  
   <add key="ConnectionString" value="actual connection string" />
  
 </appSettings>

use below code to read value from app settings.

System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]
 
Share this answer
 
Comments
A.Girish 21-Oct-13 0:14am    
How can i change the connection string manually once i created the Setup File...
Amol_B 21-Oct-13 8:15am    
Once you install your setup file, it will extract application in C:\Program Files (or other location if you chosen) Go to that location edit app.config file and save it. this way you can change connection string. Note that name of app.config file will be application.config(if your application name is abc.exe then config file will be abc.config
A.Girish 22-Oct-13 0:19am    
Thnks dude..
Use app.config file and change the connection string manuaaly, app.config file does not require to re-compile.
Or
Use following SqlConnection
C#
SqlConnection MyConnection=new SqlConnection("Server=(Local); Database=DatabaseName; Integrated Security=True");
 
Share this answer
 
v3
It is not a good idea to store the server name in code. You should always specify connection strings in your app.config file. This will enable you to change the connection string without making any changes to the code. You can change the connection string with your production server details at the time of building your setup or after the installation is complete.
 
Share this answer
 
can u post any article or process by simple example

Thank you
 
Share this answer
 
Comments
Nelek 18-Oct-13 7:53am    
Please don't post solutions to chat with people asking or answering. The messages are not always sorted by date, so it can be a bit difficult to follow them correctly.
The best option is to use the "Have a question or comment?" (or the tiny "reply" on another comment). Another advantage is, that the person you write to will get a notification, otherwise it could be that he/she doesn't see your additional question.

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