10
In the config:
<add name="ConnectionName" connectionString="Data Source=xxxx\yyyy;Initial Catalog=MyDB;User ID=userName;Password=pwd" />
In C# code:
using System.Configuration;
...
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionName"].ToString();
Better still would be to define a function and use it in the code everywhere:
public string getConnectionStringMyDB()
{
return ConfigurationManager.ConnectionStrings["ConnectionName"].ToString();
}