Configuration file not saving runtime (not debugging)
I am using the code below to save connection string during runtime (Clie)
Code:
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
the configuration is not saving however, i notice this when i restart the application and check the config from the application
How do i modify configuration settings, especially connection string at runtime (not debug)
Re: Configuration file not saving runtime (not debugging)
Does it only appear to fail to save if you make a code change and then run the project again? What if you just exit the app and run it again immediately? It may well be that your modified config file is simply being overwritten when you build again, which will happen if there's a code change.
Re: Configuration file not saving runtime (not debugging)
i am talking about a deployed vb.net application, not in visual studio
when i exit the application at start it again, after i must have supplied the correct settings, i see the old values not the new one i wanted saved