如何从C#中的控制台应用程序内的远程文件初始化连接字符串:
我目前这样做是为了让AppSettings从远程位置加载:
string 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");
Connectionstring文件示例:
<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>