简体   繁体   中英

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.

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);
            }
        }

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

After installation make sure:

  • PATH is updated with Oracle dlls location: \\product\\12.1.0\\client_1\\bin and \\product\\12.1.0\\client_1
  • Restart the server.
  • Enable 32bit for the App Pool in IIS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM