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

Topics: Data Access Application Block
Sep 5, 2012 at 1:54 PM


I am using Oracle.DataAcces for Oracle 8I and Visual Studio 2010. When I try to start a project, I got following error: “Activation error occured while trying to get instance of type Database, key “”".

The Exception is Microsoft.Practices.ServiceLocation.ActivationException on
database = EnterpriseLibraryContainer.Current.GetInstance<Database>();

The message for the InnerException is:

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

My App.config file is:

<?xml version="1.0" ?>

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<dataConfiguration defaultDatabase="DefaultConnectionString">
<add databaseType="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null" name="Oracle.DataAccess.Client"/>

<add name="DefaultConnectionString" connectionString="Data Source=toy;User ID=hr;Password=hr;Persist Security Info=True;" providerName="Oracle.DataAccess.Client"/> </connectionStrings>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342" culture="neutral"/>
<bindingRedirect oldVersion="" newVersion=""/> </dependentAssembly>



I can workaround the problem by changing the target framework from .Net Framework 4 to .Net Framework 3.5 and line in app.config to:
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data" name="Oracle.DataAccess.Client"/>

But, I still want to use .Net Framework 4 as Target framework.

How i can solve the problem?

Regards, Dmitry


Sep 6, 2012 at 3:48 AM
Edited Sep 6, 2012 at 3:49 AM

My guess is that the machine.config for .NET 4 (located in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config or C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config depending on whether the 64 bit version is being used) does not contain the the DbProviderFactories.

It should look something like:

    <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client"
description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342" />

Or you can check for differences between the .NET 3.5 (which does work) machine.config (usually located at C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG or C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG).

You can also add the above config to your app.config.

Randy Levy
Enterprise Library support engineer 

Sep 6, 2012 at 1:59 PM
Thank you very match for solving the issue.