Skip to content

Instantly share code, notes, and snippets.

@pachecoder
Created February 10, 2017 15:38
Show Gist options
  • Save pachecoder/ea8197783266109f6cdaaca3f380f1f4 to your computer and use it in GitHub Desktop.
Save pachecoder/ea8197783266109f6cdaaca3f380f1f4 to your computer and use it in GitHub Desktop.
public void ChangeConnectionString(string key)
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
var value = connectionStringsSection.ConnectionStrings[key];
connectionStringsSection.ConnectionStrings[key].ConnectionString = ConnectionString;
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("connectionStrings");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment