[英]Configuring Enterprise Library 5.0 Data Access Application Block
我正在試圖弄清楚如何配置企業庫5.0數據訪問應用程序塊。 運行我的unittest時,出現以下錯誤:
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項目的app.Config,但這沒有什么區別。
我有點卡在這里,所以任何幫助都非常感謝。
編輯:
我引用了正確的dll(來自Program Files,而不是來自源代碼),所以這不是問題。
我終於解決了這個問題:
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。 以下對我有用。 想要傳播這個詞
確保您對Microsoft.Practices.Unity.dll有適當的引用
獲取VS 2010的最新服務包
終於想通了。 我在我的webservice的類庫中使用DAAB,並認為我必須在該庫中創建一個app.config。 應該知道這不起作用。 這樣做時我的思緒可能很遙遠......
我在webservice的web.config中進行了配置,現在所有都順利運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.