我有一个连接字符串中的app.config如下从app.config中抓取动态更新连接字符串在VB.Net
<add name="CONN" connectionString="SERVER=SERVER\SQLEXPRESS;DATABASE=TRIAL_LINK;uid=sa;pwd=trial"
providerName="System.Data.SqlClient" />
我有一个名为DBLinker这里我给一个选项给用户的形式选择一些其他服务器和数据库。 例如,我选择“服务器名称”作为“MAILSERVER”和数据库作为“实际”。我使用下面的代码覆盖app.config文件。
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)
此代码后,我试图打开登录窗体的应用程序。但是,当我试图访问连接字符串在这里,它正在提取前字符串,而不是更新的字符串。
谢谢但是这个程序不能用DB来实现。 – Shruti