DataAccess block - Activation Error (again!!)

Topics: Data Access Application Block
May 28, 2011 at 9:34 AM

I'm facing the common Activation error with the data access application block (ent lib 5.0):

{"Resolution of the dependency failed, type = \"Microsoft.Practices.EnterpriseLibrary.Data.Database\", name = \"AppDB\".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.

-----------------------------------------------

At the time of the exception, the container was:

Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,AppDB"}

Here are my settings:

Calling code:

public class DataAccessHelper
    {
        private static Database _db;       

        public static string Test()
        {
            _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("AppDB");
            return _db.ConnectionString;            
        }
    }
App Config:
<?xml version="1.0" encoding="utf-8" ?>
<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="true" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
      </configSections>
  <dataConfiguration defaultDatabase="AppDB" />
  <connectionStrings>
    <add name="AppDB" connectionString="Database=****;Server=**\**;Integrated Security=SSPI"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="Policy">
        <exceptionTypes>
          <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
              postHandlingAction="NotifyRethrow" />
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
  </configuration>
The strange thing is that this exact setting works fine from a windows forms application, but gives me this activation error when used in a class library application (called by a WCF app). Not sure if that should matter.
Any assistance on this is greatly appreciated.
Thanks,
Shahnaz.
May 30, 2011 at 2:56 AM

Hi,

Are you using the config file inside your class library? If yes, your config should be placed on the application that references the class library not on the class library itself.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 30, 2011 at 6:12 AM

That's exactly what was needed. Once I moved the settings to the WCF web.config file, it worked like a charm. Thanks much.

 

Shahnaz.