3

我想弄清楚如何配置企业库5.0数据访问应用程序块。 当运行单元测试我,我得到以下错误:配置企业库5.0数据访问应用程序块

var db = DatabaseFactory.CreateDatabase("PokerAdviserProvider"); 

的App.config:

<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="false" /> 
    </configSections> 
    <dataConfiguration defaultDatabase="PokerAdviserProvider" /> 
    <connectionStrings> 
     <add name="PokerAdviserProvider" connectionString="server=(localhost);Initial Catalog=PokerAdviser;uid=abc;pwd=xyz" 
      providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
</configuration> 

我一直

Microsoft.Practices.ServiceLocation.ActivationException was caught 
    Message=Activation error occured while trying to get instance of type Database, key "PokerAdviserProvider" 
    InnerException: Microsoft.Practices.Unity.ResolutionFailedException 
     Message=Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "PokerAdviserProvider". 
Exception occurred while: while resolving. 
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value. 

的代码,我得到这个线google搜索了一下周围,发现了一些答案,这些设置也应该把我的单元测试项目的App.config中,但是这并没有有所作为。

我有点卡在这里,所以任何帮助,高度赞赏。

编辑:

我引用正确的DLL的(那些从程序文件,而不是从源代码),所以这不是problemneither。

回答

0

终于明白了。我在我的web服务的类库中使用DAAB,并认为我必须在该库中创建一个app.config。应该知道这是行不通的。我的心可能是很远很远这样做的时候...

我做的web服务的web.config中的配置和现在都顺利进行。

2

我终于解决了这个问题:

Error: Activation error occured while trying to get instance of type Database, key "<database name>" 

Inner Exception: Resolution of the dependency failed, type = Microsoft.Practices.EnterpriseLibrary.Data.Database 

我是在Windows 7上,Enlib 5.0运行VS 2010。以下为我工作。想传播字左右

  1. 确保您有Microsoft.Practices.Unity.dll

    适当的参考
  2. 获取最新的service pack,VS 2010

0

请参阅这些两个很好的职位post1 & post2有关企业库配置