1

如何在 C# 中的控制台应用程序中从远程文件初始化连接字符串:

我目前正在为 AppSettings 从远程位置加载:

字符串 runtimeAppSettingsconfigfile = "c:\Somepath\StaticAppSettings.config"

System.Configuration.Configuration config
    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.File = runtimeAppSettingsconfigfile;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

如何为连接字符串配置文件实现相同的功能,即远程加载连接字符串文件?

编辑 :

到目前为止我尝试过的是:

string runtimeConnectionStringConfigfile = "c:\somepath\StaticConnectionStrings.config"
Configuration config =                          ConfigurationManager.OpenExeConfiguration(runtimeConnectionStringConfigfile);

config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStrings");

连接字符串文件示例:

<connectionStrings>
    <add name="mydb" connectionString="Data Source=PrimaryDB;Initial Catalog=test;Persist Security Info=True;User ID=testuser;Password=test; Asynchronous Processing=true" providerName="System.Data.SqlClient" />
</connectionStrings>
4

0 回答 0