开发者

Activation error occured while trying to get instance of type Database, key

开发者 https://www.devze.com 2023-04-12 07:02 出处:网络
I have a data access layer called \'LDA\' which contains the following code: db = DatabaseFactory.CreateDatabase(\"myConn\");

I have a data access layer called 'LDA' which contains the following code:

db = DatabaseFactory.CreateDatabase("myConn");

And an app.config with the following:

<?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>

I took this out of the web.config for the presentation layer because only the LDA needs to access the database and rather than encrypting the connections strings, we wanted to just put it in the compiled dll since we need zero dynamic ability to change connection strings.

With the above in the web.config of the presentation layer project, everything works fine, but when I try to take the above and put it in the app.config of the data access project 'LDA', I get the following error:

Activation error occured while trying to get instance of type Database, key "LTTDBConn"

at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53 at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 103 at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.InnerCreateDatabase(String name) in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\DatabaseFactory.cs:line 82 at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase(String name) in e:\Builds\EntLib\Latest\Source\Blocks\Data\Src\Data\DatabaseFactory.cs:line 68 at Lisa.DataAccess.OracleHelper.DALHelper.ExecuteReader(String spName) in \DALHelper.cs:line 79

Any ideas on how to make this happen? i.e., have a webconfig in the website project and an appconfig in the data access project (that contains the db conn info)?

Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号