Search code examples
c#winformsunit-testingenterprise-librarydata-access-app-block

Configuring Enterprise Library 5.0 Data Access Application Block


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.


Solution

  • 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.