开发者

Configuring Enterprise Library 5.0 Data Access Application Block

开发者 https://www.devze.com 2023-02-24 01:40 出处:网络
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:

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.CreateDatab开发者_开发问答ase("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.


I finally fixed this problem:

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

I was running VS 2010 on windows 7, Enlib 5.0. The following worked for me. Wanted to spread the word around

  1. Make sure you have proper reference to Microsoft.Practices.Unity.dll

  2. Get the latest service pack for VS 2010


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.


Refer to these two good posts post1 & post2 about Enterprise Library Configuration

0

精彩评论

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

关注公众号