Hi,
I want to be able to change my web site web.config dynamically so that any time i made changes to the application i don't need to download the web config and re-upload, i have tried the following
// =========================================== // The content of pathname is shown below // string pathname = "~/web.config"; //============================================ System.Configuration.Configuration Config1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(pathname); ConnectionStringsSection conSetting = (ConnectionStringsSection)Config1.GetSection("connectionString"); ConnectionStringSettings StringSettings = new ConnectionStringSettings("NIQSDB", "Data Source=" + ServerName + ";Database=" + DBaseName + ";User ID=" + UserID + ";Password=" + PSSWD + ";"); conSetting.ConnectionStrings.Remove(StringSettings); conSetting.ConnectionStrings.Add(StringSettings); Config1.Save(ConfigurationSaveMode.Modified);
and i get the following error :
Object reference not set to an instance of an object.
at
conSetting.ConnectionStrings.Remove(StringSettings);
please what am i doing wrongly.
thank you