Data Access Block working with .NET 2.0 however creating issues with .NET 4.0 target.

Topics: Data Access Application Block
Jun 15, 2011 at 12:15 PM
Edited Feb 29, 2012 at 4:13 AM

I am using Data Access Application block, with the below configuration.

<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"/>
    </configSections>
  <dataConfiguration defaultDatabase="Database Connection String">
   
  </dataConfiguration>
<connectionStrings>
    <add name="Database Connection String" connectionString=" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" providerName="Oracle.DataAccess.Client"/>
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

I am creating the database instance in this fashion.

Database db = DatabaseFactory.CreateDatabase("Database Connection String");

 

When the target framework is changed to v2.0 then the above line is throwing

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

Need help on why I am getting this error only for .NET 4.0 but not for 2.0

Thanks.

Jun 15, 2011 at 4:49 PM

Hi,

One question is where are you referencing your Data assemblies from? Is it from GAC?

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 16, 2011 at 8:39 AM

I am referencing all the Enterprise Lib dlls from "C:\Program Files\Microsoft Enterprise Library 5.0\Bin" location.

Jun 16, 2011 at 9:44 AM
Edited Jun 16, 2011 at 9:46 AM

Hi,

Are you using ODP.NET as your data provider? If yes then you will need to add provider mappings to your configuration file. For more details, you can refer here.

 

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

Jun 16, 2011 at 12:12 PM
Edited Feb 29, 2012 at 4:14 AM

Thanks for your response. I have also tried in that fashion. However, its working with .NET 2.0 and when I change the Target Framework to .NET 4.0 for my project its failing. Here is the configuration.

 

 

<configuration>
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" requirePermission="true"/>
    </configSections>
  <dataConfiguration defaultDatabase="ConnectionString">
    <providerMappings>
      <add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data" name="Oracle.DataAccess.Client"/>
    </providerMappings>
  </dataConfiguration>
<connectionStrings>
    <add name="ConnectionString" connectionString="XXXXXXXXXXXXXXXXXXXXXXXXXXX" providerName="Oracle.DataAccess.Client"/>
</connectionStrings>

I couldnt understand what I'm missing. Why is it only happening if I choose the Target Framework for my project to .NET 4.0. Please advice.

Jun 17, 2011 at 6:29 AM

Hi,

Have you downloaded the latest version of ODP.NET. I suspect the current version of your ODP.NET doesn't support Framework 4.0.

 

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

Jul 12, 2011 at 12:54 PM

I have customized the Enterprise Library Source code and am using the compiled dlls from the Source code. These are having "PublicKeyToken" as "null" as they are compiled (my understanding).

Except "Microsoft.Practices.ServiceLocation.dll" all the other dlls referenced for my DataAcess Blocks are not having strong name. As there is no source code for the ServiceLocation dll.

Now, I am getting below error while trying to create my ODP.NET 4.0 connection at

Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("ConnectionString"

); 

 

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

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

Please suggest, I am using compiled version of "Microsoft.Practices.EnterpriseLibrary.Data.dll".

Jul 13, 2011 at 1:56 AM

Hi,

Have you already modified your config and added provider mappings for ODP.NET? Take a look on this article, how it is done.  

 

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