Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 388
The Light Avatar asked Jul 02 '13 12:07

The Light


2 Answers

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);
            }
        }
like image 189
David Zambrano Avatar answered Sep 22 '22 11:09

David Zambrano


Oracle.DataProvider version 2.102.2.20 decrypted

2: .Net version (can be 1 for .Net 1 - 1.1, 2 for 2 - 3.5 and 4 for 4 - 4.5)

102: Oracle version: Oracle 10.2

2.20: Oracle Data access version

You should check

  1. .Net version (should not be higher than your .Net compiler)

  2. Oracle client version (should not exceed Oracle Client version)

  3. Both Oracle client and Oracle.DataProvider are 64-bit or Oracle.DataProvider is 32 bit and Oracle client is either 32 bit or supports legacy 32 bit mode

like image 25
Dmitry Bychenko Avatar answered Sep 20 '22 11:09

Dmitry Bychenko