Search code examples
c#.netoracleodp.net

ODP.NET Managed - Unable to find requested .Net Framework Data Provider


Using Visual Studio 2013, I've added the latest version of ODP.NET Managed to a project using Nuget:

Install-Package odp.net.managed

http://www.nuget.org/packages/odp.net.managed/121.1.2

Now, when I try to run the following code:

Database db = DatabaseFactory.CreateDatabase();

It throws the following exception:

An exception of type 'System.ArgumentException' occurred 
in System.Data.dll but was not handled in user code
Additional information: Unable to find the requested .Net
Framework Data Provider.  It may not be installed.

After reading of other users's similar issues, I added the Managed driver section to C:\Windows\Microsoft.Net\Framework64\v4.0.30319\Config\machine.config:

<system.data>
        <DbProviderFactories><add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
        <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>

But that had no affect.

I have the connection string specified as such in my web.config, but I'm not sure if it is even looking at the connection string format as it is failing before I open the connection:

<connectionStrings>
    <add name="OneCDPBuild" 
    providerName="Oracle.ManagedDataAccess.Client" 
    connectionString="Data Source=database;user id=IDhere;pwd=passwordhere;" />
  </connectionStrings>

I added the following to my web config:

<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>

Solution

  • I would start by doing a direct test and avoiding the factory methods:

    var conn = new Oracle.ManagedDataAccess.Client.OracleConnection("your connection string");
    conn.Open();
    

    Any issues here will either be related to the Oracle.ManagedDataAccess.dll missing from the bin directory, or connectivity issues caused by the connection string (assuming you can already connect to the oracle instance via other means).

    As for the factory, it looks like you're using some out of date enterprise library code. In later versions of the framework I believe you would use:

    var factory = DbProviderFactories.GetFactory("ODP.NET, Managed Driver");
    var conn = factory.CreateConnection();
    

    I think if you take it one step at a time you'll get better feedback.