【问题标题】:Configuring Enterprise Library 5.0 Data Access Application Block配置 Enterprise Library 5.0 数据访问应用程序块
【发布时间】:2011-04-10 00:18:59
【问题描述】:

我正在尝试弄清楚如何配置企业库 5.0 数据访问应用程序块。 运行我的单元测试时,我收到以下错误:

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.

我得到这个的代码行:

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>

我在谷歌上搜索了一下,发现了一些答案,这些设置也应该放在我的 unittest-project 的 app.Config 中,但这并没有什么不同。

我有点卡在这里,所以非常感谢任何帮助。

编辑:

我引用了正确的 dll(来自 Program Files 的那些,而不是来自源代码的),所以这也不是问题。

【问题讨论】:

    标签: c# winforms unit-testing enterprise-library data-access-app-block


    【解决方案1】:

    我终于解决了这个问题:

    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 上运行 VS 2010,Enlib 5.0。以下对我有用。想广而告之

    1. 确保您正确引用了 Microsoft.Practices.Unity.dll

    2. 获取 VS 2010 的最新服务包

    【讨论】:

      【解决方案2】:

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

      我在webservice的web.config中做了配置,现在一切运行顺利。

      【讨论】:

        【解决方案3】:

        参考这两个关于企业库配置的好帖子post1 & post2

        【讨论】:

          猜你喜欢
          • 2011-04-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-21
          • 2011-02-20
          • 2011-04-29
          相关资源
          最近更新 更多