How to fix "The provider is not compatible with the version of Oracle client"?

The Light picture The Light · Jul 2, 2013 · Viewed 39.8k times · Source

We're using the Oracle.DataAccess.dll assembly version 2.102.2.20 (32 bit).

I deployed our Web API application to IIS and tried openning and closing a connection:

 private static void CheckConnectionUsingOracleClient(string connection)
        {
            var logger = DiContainer.Resolve<ILogger>();

            try
            {
                logger.LogInfo("Trying to connect to " + connection);
                // check whether you can connect to the shop using Oracle.DataAccess
                using (var cnn = new Oracle.DataAccess.Client.OracleConnection(connection))
                {
                    cnn.Open();
                    cnn.Close();
                }

                logger.LogInfo("Succeeded to connect to " + connection);
            }
            catch (System.Exception ex)
            {
                logger.LogError("Failed to connect to " + connection, ex);
            }
        }

On my local machine it's fine, but on this server it throws an exception when trying to initalize the the OracleConnection:

The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client

I've installed Oracle client 11.2 (32 bit) on the server and I can see that in the GAC (c:\windows\assembly) the Oracle.DataAccess assembly is installed in 32 bit Processor Architecture. It works fine on one of our servers but not this one.

In IIS also, I've set 'Enable 32 bit Application' on the Application Pool.

How can it be fixed? I've spent over 10 hours so far trying different things :(

I'd ideally like to be able to use Oracle.DataAccess.dll without the need to install an Oracle Client on the server.

Answer

David Zambrano picture David Zambrano · Oct 9, 2016

you can install Oracle.ManagedDataAccess using Package Manager Console nuget

Pm> Install-Package Oracle.ManagedDataAccess

ODP.NET, Managed Driver is a 100% native .NET code driver. No additional Oracle Client software is required to be installed to connect to Oracle Database.

Update Code

using Oracle.ManagedDataAccess.Client;
private static void CheckConnectionUsingOracleClient(string connection)
        {
            var logger = DiContainer.Resolve<ILogger>();

            try
            {
                logger.LogInfo("Trying to connect to " + connection);
                // check whether you can connect to the shop using Oracle.DataAccess
                using (var cnn = new OracleConnection(connection))
                {
                    cnn.Open();
                    cnn.Close();
                }

                logger.LogInfo("Succeeded to connect to " + connection);
            }
            catch (System.Exception ex)
            {
                logger.LogError("Failed to connect to " + connection, ex);
            }
        }