I have a connection string as follows in app.config
<add name="CONN" connectionString="SERVER=SERVER\SQLEXPRESS;DATABASE=TRIAL_LINK;uid=sa;pwd=trial"
providerName="System.Data.SqlClient" />
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.