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

Topics: Data Access Application Block
May 5, 2011 at 1:14 AM

Hi,


I am building a 32 bit dotnet application on a 64-bit machine(developing on 64-bit, to be deployed on 32-bit) having windows server 2008 R2 operating system.

I use the 64-bit IBM DB2 9.5.4 runtime client. I am able to connect to database through command prompt using testconn.exe command, but it throws up an error while connecting through dotnet enterprise library 5.0 saying "The type database cannot be constructed. you must configure the container to supply this value" at the following line.

 public DatabaseManager()
        {
            try
            {
                db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
            }
            catch
            {
                throw;
            }
        }

Following is my connection string in web.config.
<dataConfiguration defaultDatabase="MyDatabase" />
<connectionStrings>
<add name="MyDatabase" connectionString="Database=<dbname>;CurrentSchema=<schema>;User ID=<user>;Password=<pass>;"
providerName="IBM.Data.DB2.9.5.4" />
</connectionStrings>

Please help.

May 5, 2011 at 2:02 AM

Hi,

I guess you are trying to use IBM DB2 here as your database?  Then you need  to create a wrapper for DB2 provider and define it inside the providerMappings. For example you have a wrapper named DB2Database, your config will look like this:

 <providerMappings>
      <add databaseType="CustomDatabaseProvider.DB2Database, CustomDatabaseProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="IBM.Data.DB2" />
  </providerMappings>

Also, register the DB2 provider to your config. It will look like this:

 <system.data>
  <DbProviderFactories>
   <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=9.0.0.2, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />
  </DbProviderFactories>
 </system.data>

 

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

May 5, 2011 at 10:10 PM
Edited May 5, 2011 at 10:11 PM

Hi,

Thanks for the reply!!

So, you mean to include these 2 tags in web.config file? Or in machine.config? Do we need to write any other code for the wrapper?

May 6, 2011 at 3:09 AM

Yes, you need to add it to your web.config. You also need to write the code for the wrapper. If you want to, you can send us your email so we can send you the sample project for creating a custom database provider using DB2.

 

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