I am using the code below to save connection string during runtime (Clie)
the configuration is not saving however, i notice this when i restart the application and check the config from the applicationCode:Try connStr = String.Format("SERVER={0}; PORT={1}; USER={2}; PWD={3}; DATABASE={4};", _ txtServer.Text, nudPort.Value, txtUser.Text, txtPass.Text, txtDB.Text) Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) Dim section As ConnectionStringsSection = DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection) section.ConnectionStrings("MySQL").ConnectionString = connStr If section IsNot Nothing Then If Not section.IsReadOnly() Then section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider") section.SectionInformation.ForceSave = True config.Save(ConfigurationSaveMode.Modified) End If End If ConfigurationManager.RefreshSection("connectionStrings") Catch ex As Exception ShowMessage(String.Format(My.Resources.error_item_failed, "save", "Config"), MessageBoxIcon.Information) End Try
How do i modify configuration settings, especially connection string at runtime (not debug)


Reply With Quote
