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

Topics: Data Access Application Block
Mar 2, 2011 at 3:28 PM

I am a first time user of Data Access Application block in Enterprise Library 5.

I downloaded Hands On Labs for it from MSDN site and using the first excercise. I modified it slightly to use it against Oracle so my provider is Oracle.DataAccess.Client.

I migrated the lab project to use VS.NET 2010 (with .NET 3.5) and it worked perfect and was able to get data from Oracle table.

But when I changed the target to .NET 4.0, the same code base gave an exception with error: "Activation error occured while trying to get instance of type Database"

I have checked that Microsoft.Practices.EnterpriseLibrary.Data has copylocal as true.

Here is the app.config:

<?xml version="1.0"?>
    <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"/>
  <dataConfiguration defaultDatabase="QuickStarts Instance"/>
    <add name="QuickStarts Instance" connectionString="User ID=XYZUser;Data Source=CDB;Password=XYZPass" providerName="Oracle.DataAccess.Client"/>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

private void mnuCount_Click(object sender, System.EventArgs e) { // TODO: Count Customers Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("QuickStarts Instance"); int count = Convert.ToInt32(db.ExecuteScalar( CommandType.Text, "SELECT COUNT(*) FROM ABC_OUT")); string message = string.Format( "There are {0} customers in the database", count.ToString()); MessageBox.Show(message); }

Let me know what I am doing wrong here.

Mar 2, 2011 at 4:39 PM

Never mind.

Its the version of Oracle ODAC that was causing issues.

You have to use at least ODAC 11.2 Release 3 ( with Oracle Developer Tools for Visual Studio to make it work with Enterprise Library 5.0 DAAB.