This blog shows on how to manipulate an ADO.NET connection string using C#.
public static void AddAndSaveOneConnectionStringSettings(
System.Configuration.Configuration configuration,
System.Configuration.ConnectionStringSettings connectionStringSettings)
{
ConnectionStringsSection connectionStringsSection = configuration.ConnectionStrings;
connectionStringsSection.ConnectionStrings.Add(connectionStringSettings);
configuration.Save(ConfigurationSaveMode.Minimal);
// ConfigurationManager
ConfigurationManager.RefreshSection("connectionStrings");
}