Changing the Web.Config's connectionstring section
Many people ask me how they can change or add a new connectionstring in Web.Config's connectionstring section. Basically you only need import the System.Web.Configuration namespace, open the Web.Config file where is connectionstrings section and change or add a new connectionstring. An example is:
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~");
ConnectionStringsSection dbConnString = webConfig.ConnectionStrings;
//Changing
dbConnString.ConnectionStrings["DBOrders"].ConnectionString = "YOUR NEW CONNSTRING HERE";
//Adding
dbConnString.ConnectionStrings.Add(
new ConnectionStringSettings("MDBTest", "MDB ConnString", "System.Data.OleDb"));
webConfig.Save();