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

Topics: Data Access Application Block
Aug 17, 2011 at 10:06 AM

Hi,

After migrating from Entlib 2.0 to EntLib 5.0, my application is not able to connect to database. It throws an runtime error saying "Activation error occured while trying to get instance of type Database, key "MY_DB"..... The type Database cannot be constructed. You must configure the container to supply this value."

I am getting this error when I use any of the below statements:

OracleDatabase database = (OracleDatabase)DatabaseFactory.CreateDatabase("SWB_DB" 

);

 

 

 

 

Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("SWB_DB");

 

 

 

Could you let me know if you have any solution for this issue.

Thanks,

Vijay

Aug 18, 2011 at 3:55 AM

Hi,

Can you also post your configuration here?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 18, 2011 at 6:56 AM

Hi Noel,

Please find below my config settings:

 

<?xml version="1.0"?>
<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="oracleConnectionSettings" type="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration.OracleConnectionSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
 </configSections>
  <dataConfiguration defaultDatabase="ABCDB" />
 <connectionStrings>
  <add name="ABCDB" connectionString="Data Source=ABCTEST;User ID=ABC;Password=ABC;Persist Security Info=False;"
   providerName="System.Data.OracleClient" />
 </connectionStrings>
 <oracleConnectionSettings>
  <add name="ABCDB"/>
 </oracleConnectionSettings>
 <system.web>
  <compilation debug="true" targetFramework="4.0">
   <assemblies>
    <add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
  <authentication mode="Forms">
   <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
  </authentication>
  <membership>
   <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
   </providers>
  </membership>
  <profile>
   <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
   </providers>
  </profile>
  <roleManager enabled="false">
   <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
   </providers>
  </roleManager>
  <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>
</configuration>

Aug 18, 2011 at 7:17 AM

Your config seems fine. Did you also migrated to .NET Framework 4.0? I'm not sure but this might have something to do with System.Data.OracleClient being deprecated at .NET 4.0 (details found here). The ADO.NET team strongly recommends the users should use other ADO.NET providers for Oracle.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 19, 2011 at 11:09 AM

Hi Noel,

Yes, I migrated to .NET 4.0.

I found that the same application is connecting to DB when I run on Windows 7 machine and not connecting when I run on Windows 2003 Server. Could you please let me know if Entlib is dependent on OS.

Thanks,

Vijay

Aug 19, 2011 at 11:55 AM

It seems that Windows 2003 is not supported by Enterprise Library 5.0 as per with Enterprise Library 5.0 System Requirements.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us