Problems switching .NET project from unmanaged to managed ODP.NET assemblies

Tom Halladay picture Tom Halladay · Mar 14, 2014 · Viewed 7.7k times · Source

I'm trying to switch my .NET project over to the manage oracle to make deployments easier. However I'm getting the following error in my test Win Server 2013 environment:

Unable to determine the provider name for connection of type 'Oracle.ManagedDataAccess.Client.OracleConnection'.

Steps I've taken so far:

  1. Removed all Oracle.DataAccess dll's and references from the solution
  2. Added the Oracle Data Provider for .NET (ODP.NET) Managed Driver in the NuGet package manager
  3. Switched all Imports Oracle.DataAccess statements over to Imports Oracle.ManagedDataAccess

I'm not getting any build errors, and the project runs fine locally. However when deployed to the testing environment, I get this error. The test environment is Windows Server 2012, and has a legacy Oracle 11.2.0 client tools installation present.

This is my connection creation code:

Public Sub New()
    MyBase.New(
        New OracleConnection(
            ConfigurationManager.ConnectionStrings("Entities").ConnectionString),
        True)
End Sub

Here are 3 different styles of connection configs that I have tried (both work locally, but yield the same problem on the test environment)

(formatted for visibility)

  <add 
      name="Entities"
      connectionString="
          Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=###.###.###.###)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=______)));
          User Id=_____;
          Password=_____;"
      providerName="Oracle.ManagedDataAccess.Client" />

  <add 
      name="Entities"
      connectionString="
          Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=###.###.###.###)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=______)));
          User Id=_____;
          Password=_____;"
      providerName="Oracle.DataAccess.Client" />

  <add 
      name="Entities"
      connectionString="
          Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=###.###.###.###)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=______)));
          User Id=_____;
          Password=_____;"
   />

Any help would be greatly appreciated!

Answer

Tom Halladay picture Tom Halladay · Mar 14, 2014

Manual Download Method

Thanks to @Christian Shay for pointing out that the NuGet version of Managed ODAC is not authored by Oracle

To use Managed Oracle Data Access with Entity Framework, in Visual Studio 2012 (.NET 4.5):

  1. Pull down Entity Framework 5.0.0.0

    Install-Package EntityFramework -Version 5.0.0

  2. Download the latest Oracle Data Access Components (ODAC)

  3. Manually reference Oracle.ManagedDataAccess.dll

  4. Add this section to the config file

  <system.data>
    <DbProviderFactories>
      <remove invariant="Oracle.ManagedDataAccess.Client" />
      <add name="ODP.NET, Managed Driver"
           invariant="Oracle.ManagedDataAccess.Client"
           description="Oracle Data Provider for .NET, Managed Driver"
           type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>

And then proceed as usual. It appears at this time that Entity Framework 6 does not support Oracle.ManagedDataAccess yet, so it is necessary to run version 5.

Also keep in mind that if you are using Visual Studio 2010 or earlier, targeting .NET 4, NuGet will pull down EF5, but use the 4.x assemblies. I have not tested this on VS2010 with .NET 4.