Look at here:
Connection strings and configuration files
Using the configuration file, you just need to change the connection string to the configuration file after deploying your application.
Here is a way to do what you want:
From http://www.dreamincode.net/forums/topic/70745-connection-string-in-appconfig/
The contents of your configuration file:
<connectionStrings >
<add name="YourName"
connectionString="Provider=msdaora;Data Source=MyOracleDB;Persist Security Info=False;Integrated Security=Yes;"
providerName="System.Data.OracleClient" />
</connectionStrings>
The way to get the connection string at runtime:
public static string GetConnectionString(string strConnection)
{
string sReturn = new string("");
if (!string.IsNullOrEmpty(strConnection))
{
sReturn = ConfigurationManager.ConnectionStrings(strConnection).ConnectionString;
}
else
{
sReturn = ConfigurationManager.ConnectionStrings("YourConnectionString").ConnectionString;
}
return sReturn;
}
Using the method:
string connectionString = GetConnectionString("YourName");
source
share