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.
<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
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["localSystemDB"].ToString());
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["remoteSystemDB"].ToString());
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["backupServer"].ToString());
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