【发布时间】:2016-04-05 17:29:26
【问题描述】:
我正在尝试使用 EntLib 将连接字符串移动到外部文件,但是
ConfigurationManager.ConnectionStrings 只给了我默认的 ASP.NET 数据库,它甚至不在配置中。
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
我希望从 shared.config 中看到两个连接字符串。 可能是什么问题,或者我对此功能的理解有误?
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
<sources>
<add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Shared" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
filePath="shared.config" />
</sources>
<redirectSections>
<add sourceName="Shared" name="connectionStrings" />
</redirectSections>
</enterpriseLibrary.ConfigurationSource>
</configuration>
shared.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="connStr1" connectionString="Data Source=local;Initial Catalog=DB1;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="connStr2" connectionString="Data Source=local;Initial Catalog=DB2;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
【问题讨论】:
标签: c# .net app-config enterprise-library enterprise-library-5