Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
i developed as project...i can access database only in my system..
i want to install the setup file of project in other system...the LAN was connected ...then what can i do?
i know about connection can be change, but how to write the connection string ?
any changes in manually in computer connection ?



Regards
Anand Rajan
Posted
Updated 16-Dec-13 20:06pm
v4

1 solution

Hi Joy,

You can use web.config file to add one or more connection string,
Here is the sample connection string with three different servers.
XML
<connectionStrings>
<add name="localSystemDB" connectionString="Server=.\SQL2008;Database=DBName;User ID=username;Password=XXXXX;" providerName="System.Data.SqlClient"/>
<add name="remoteSystemDB" connectionString="Server=ipaddress\SQL2008R2;Database=DBName;ID=username;Password=XXXXX;" providerName="System.Data.SqlClient"/>
<add name="backupServer" connectionString="SERVER=backupsrvrIPaddress\SQL2008R2;DataBase=DBName;ID=username;Password=XXXXX;" providerName="System.Data.SqlClient"/>
 </connectionStrings>

In Code behind you can use like this
C#
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["localSystemDB"].ToString()); //For localSystemDB
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["remoteSystemDB"].ToString()); //For remoteSystemDB
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["backupServer"].ToString()); //For backupServer

Updated solution:

As you have mentioned 3 connection string in your web.config, your application need to know which connection string should be used at runtime.
So we need to mention the application to use appropriate connection string by using the above code behind code.
If you use first code then "localSystemDB" connection string will be used in the applicaiton.
Whereas if you use second connection string you will be connected to "remoteSystemDB" from your application.
If you use third one then you will be pointed to "backupServer" from your application.



Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v2
Comments
An@nd Rajan10 16-Dec-13 0:58am    
thank you..
you write like "In Code behind you can use like this " what is this and what is the use of this...will you can explain...please..
♥…ЯҠ…♥ 16-Dec-13 1:11am    
updated my solution as per your comments.
An@nd Rajan10 16-Dec-13 1:16am    
thank u
An@nd Rajan10 16-Dec-13 1:33am    
Sure

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