我有一个名为'LDA'的数据访问层,它包含以下代码:
db = DatabaseFactory.CreateDatabase("myConn");
带有以下内容的app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="oracleConnectionSettings" type="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="myConn">
<providerMappings>
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data"
name="Oracle.DataAccess.Client" />
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="System.Data.OracleClient" />
</providerMappings>
</dataConfiguration>
<oracleConnectionSettings>
<add name="myConn"></add>
</oracleConnectionSettings>
<connectionStrings>
<add name="myConn" connectionString="user id=xxxx;password=xxxx;Data Source=XXXX; Connection Lifetime=60;Pooling=true;Min Pool size=5;"
providerName="System.Data.OracleClient" />
</connectionStrings>
</configuration>
我从web.config中取出了表示层,因为只有LDA需要访问数据库而不是加密连接字符串,我们只想把它放在已编译的dll中,因为我们需要零动态能力改变连接字符串。
使用上面的表示层项目的web.config,一切正常,但是当我尝试将上面的内容放在数据访问项目'LDA'的app.config中时,我得到以下内容错误:
尝试获取数据库类型的实例时出现激活错误,键“LTTDBConn”
位于c:\ Home \ Chris \ Projects \ CommonServiceLocator \ main \ Microsoft.Practices.ServiceLocation \ ServiceLocatorImplBase.cs中的Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(类型serviceType,String key):第53行 at c:\ Home \ Chris \ Projects \ CommonServiceLocator \ main \ Microsoft.Practices.ServiceLocation \ ServiceLocatorImplBase.cs中的Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance [TService](String key):第103行 位于e:\ Builds \ EntLib \ Latest \ Source \ Blocks \ Data \ Src \ Data \ DatabaseFactory.cs中的Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.InnerCreateDatabase(String name):第82行 位于e:\ Builds \ EntLib \ Latest \ Source \ Blocks \ Data \ Src \ Data \ DatabaseFactory.cs中的Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase(String name):第68行 在\ DALHelper.cs中的Lisa.DataAccess.OracleHelper.DALHelper.ExecuteReader(String spName):第79行
有关如何实现这一目标的任何想法?即,在网站项目中有一个webconfig,在数据访问项目中有一个appconfig(包含db conn信息)?
谢谢!