Configuring Enterprise Library 5.0 Data Access Application Block

14,203

Solution 1

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.

Solution 2

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

Share:
14,203
Koen
Author by

Koen

.NET developer

Updated on September 04, 2022

Comments

  • Koen
    Koen over 1 year

    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.