我有一個連接字符串中的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