Create an Extension for DB2-Database

Topics: Building and extending application blocks, Data Access Application Block
Mar 30, 2011 at 8:08 AM


I try to create an extension for the DAAB to support DB2.

I created a class derived from the Database class and configured the app.config to use the new provider.

But every time I try to access via the configured connection I got the following exception:

Activation error occured while trying to get instance of type Database, key "DB2"

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "DB2".
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,DB2

The type Database cannot be constructed. You must configure the container to supply this value.


Does any one know how to handle this error or has got a working extension for the DB2?



Mar 30, 2011 at 10:17 AM
Edited Mar 30, 2011 at 10:20 AM


There are many reasons why you are getting this exception. Kindly check if any of the following solves your issue:

  1. Make sure your database connection strings are defined in your executable project’s configuration file.
  2. If you’re resolving a default Database instance, make sure that you set the Default Database property of the Database Settings.
  3. If you’re not resolving a Database instance, check if the providerName attribute of the connection string you’re using is properly set. It should be the correct type name. For example, if your connection string is a SQL connection string, it should be System.Data.SqlClient instead of just SqlClient. Use the Enterprise Library Configuration Tool to simplify this task and avoid mistyping.
  4. If you’re resolving a custom database provider, make sure that your custom database’s provider factory has a corresponding entry in your machine.config’s <system.Data><DbProviderFactories> section. Here’s a sample of the entry for the DB2 provider:

   <add name="IBM DB2 .NET Data Provider" invariant="IBM.Data.DB2" description="IBM DB2 Data Provider for .NET Framework 2.0" type="IBM.Data.DB2.DB2Factory, IBM.Data.DB2, Version=, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />

   5. There’s an issue when referencing the Microsoft.Practices.EnterpriseLibrary.Data assembly from GAC.   This is listed in the Enterprise Library 5.0 Known Issues and logged in the Issue Tracker. For the details and workaround, refer to this link.


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.

Mar 30, 2011 at 12:02 PM


The DbProviderFactories entries were not entered in the machine.config file for .net framework 4.0.

After I looked into the config for .net 3.5 I found the entries.

After compiling the application under .net 3.5 it works perfectly.

thanks for your help.