Fetching dynamically updated connection string from app.config in VB.Net-Collection of common programming errors
I have a connection string as follows in app.config
I have a form called DBLinker where i am giving an option to the user to select some other server and database. For instance i am selecting Server name as “MAILSERVER” and database as “Actual”. I am overwriting the app.config file using the following code.
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim mySection As ConnectionStringsSection = DirectCast(config.GetSection("CONN"),ConnectionStringsSection)
Dim conStr As String = "SERVER=MAILSERVER;DATABASE=Actual;uid=sa;pwd=trial"
config.ConnectionStrings.ConnectionStrings("CONN").ConnectionString = conStr
config.Save(ConfigurationSaveMode.Full)
ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name)
After this code i am trying to open a login form for the application. But when i am trying to access connection string here, it is fetching the former string instead of the updated one.