How to successfully use EntLibContrib.Data.OdpNet

Topics: User Discussion
Nov 8, 2011 at 8:51 AM


I've installed the OdpNet provider from Oracle and downloaded the latest EntLibContrib binaries and copied them into the Enterprise Library 5.0 folder but try as I might, I can't utilise the OdpNet provider successfully. I have the following in my app.config file:


<?xml version="1.0" encoding="utf-8" ?>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>

      <add name="EntLibContrib.Data.OdpNet"
        description="EntLibContrib Data OdpNet Provider"
        type="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null" />

  <dataConfiguration defaultDatabase="MyConnectionName">
      <add databaseType="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null"

    <add name="MyConnectionName"" connectionString="Data Source=MyDBName;User id=MyUserId;Password=MyPassword;" providerName="EntLibContrib.Data.OdpNet"/>

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

which I've checked against the QuickStart example given for OdpNet (I also can't get the example running but due to an unrelated issue) and I can't see anything different.

I have tried both the following options to create a connection:

databaseChosen = DatabaseFactory.CreateDatabase();

databaseChosen = DatabaseFactory.CreateDatabase("MyConnectionName");

but both return the following error:


The type 'EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.


Am I missing some vital step?


Nov 8, 2011 at 3:11 PM

The config looks right and the code too.

Given the error message, I'm guessing that some EntLib assemblies are missing (Data, Common, Unity, etc.). The easiest way to add the right set of assemblies is to use NuGet and add a reference to the "Enterprise Library 5.0 - Data Access Application Block" package.

Let me if that work!


Nov 8, 2011 at 5:13 PM

I tried using NuGet to add the DAAB but I still get the same error.

For reference, in case I did it wrong, after installing NuGet I used Tools -> Library Package Manager -> Manage NuGet Packages... and searched for the DAAB and clicked install. I did this for every project I had in the Solution where I was already referencing the Data and Common dlls. I only wonder if I used the wrong approach here as I already have EntLib 5.0 installed and using NuGet it downloaded dlls to a separate folder rather than use the installed dlls.

Nov 8, 2011 at 6:15 PM

You need to make sure that you are referencing the 5.0.505.0 version of the Data and Common assemblies (and not the 5.0.4xx version). If you reference the EntLib assemblies from the GAC, that might indeed be the issue.

To ensure that everything is properly in place, I would recommend to start from scratch by removing any reference to EntLib and EntLibContrib. And simply add a reference to the "EntLibContrib 5.0 - Oracle ODP.NET Data Provider" package and let NuGet resolve all the dependencies for you.

Then make sure you're not referencing any EntLib/Contrib assemblies from the GAC.

Nov 9, 2011 at 12:30 PM
Edited Nov 9, 2011 at 12:30 PM

I removed the lot and tried as you suggested but that still didn't work. In the end I created a brand new project and tried it there and it worked. The new project was just a single project, once I increased the complexity and split it into multiple projects I started to experience the same issue. It transpires a reference was missing from my main project which I've never had (in other projects) to add anything special to. Obviously because I'm using the OdpNet provider this time round I'd missed that I hadn't added a reference to EntLibContrib.Data.OdpNet. All sorted now, thank you for your help!

On a side note, after I'd proved it worked, I removed the NuGet packages and just referenced what was needed (Data, Common and OdpNet) but I'm wondering whether really I should rely on NuGet and leave the other references in place in case of future dependencies?

Nov 9, 2011 at 4:35 PM

By relying on NuGet, you get easy update support in case a new version of the package is released.

However, some people prefer to centralize their 3rd party assemblies in a custom folder, check them in their source control system and make all their projects references those assemblies. And then manually update those 3rd party assembly manually.

It's really up to you ;-)