配置 Enterprise Library 5.0 数据访问应用程序块
我试图弄清楚如何配置企业库 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>
我一直在谷歌上搜索了一下,找到了一些答案,这些设置也应该放在我的 app.Config 中unittest-project,但这没有什么区别。
我有点被困在这里,所以非常感谢任何帮助。
编辑:
我引用了正确的dll(来自Program Files的dll,而不是来自源代码的dll),所以这也不是问题。
I'm trying to figure out how to configure the enterprise library 5.0 Data Access Application Block.
When running my unittest, I get the following error:
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.
The line of code where I get this:
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>
I've been googling around a bit and found some answers that these settings should also be put in the app.Config of my unittest-project, but that didn't make a difference.
I'm a bit stuck here, so any help is highly appreciated.
Edit:
I referenced the correct dll's (the ones from Program Files, not from the source code), so that isn't the problemneither.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我终于解决了这个问题:
我在 Windows 7、Enlib 5.0 上运行 VS 2010。以下内容对我有用。想要传播信息
确保您正确引用了 Microsoft.Practices.Unity.dll
获取最新的服务包VS 2010
I finally fixed this problem:
I was running VS 2010 on windows 7, Enlib 5.0. The following worked for me. Wanted to spread the word around
Make sure you have proper reference to Microsoft.Practices.Unity.dll
Get the latest service pack for VS 2010
终于想通了。我在 Web 服务的类库中使用 DAAB,并认为我必须在该库中创建一个 app.config。应该知道这是行不通的。当我这样做时,我的思绪可能很遥远......
我在网络服务的 web.config 中进行了配置,现在一切运行顺利。
Finally figured it out. I use the DAAB in a class-library of my webservice and thought I had to create an app.config in that library. Should have know that this could not work. My mind was probably far far away when doing this...
I did the configuration in the web.config of the webservice and all runs smoothly now.
参考这两篇好帖子 post1 & post2 关于企业库配置
Refer to these two good posts post1 & post2 about Enterprise Library Configuration