hello sir
thankz for keep on supporting me . my problem is i need to update only the database name in current connection string in web.config at run-time....
this is the sample code .. to update connection string . but it updates the name of connection string i need to change the databse name of connection string !
can u please help me in this
public static void UpdateConnection(string name, string connString) { var webConfig = new ExeConfigurationFileMap { ExeConfigFilename = GlobalSettings.FullpathToRoot + "web.config" }; var config = ConfigurationManager.OpenMappedExeConfiguration(webConfig, ConfigurationUserLevel.None); var section = (ConnectionStringsSection)config.GetSection("connectionStrings"); if (section.ConnectionStrings[name] != null) { // Update the connectionstring if it exist section.ConnectionStrings[name].ConnectionString = connString; config.Save(); ConfigurationManager.RefreshSection("connectionStrings"); } else { // ...otherwise we add a new AddConnection(name, connString); } }