C# 如何修复“提供程序与 Oracle 客户端版本不兼容”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17425538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:28:07  来源:igfitidea点击:

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

c#asp.netoracledata-accessoracle-client

提问by The Light

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

我们使用的是 Oracle.DataAccess.dll 程序集版本 2.102.2.20(32 位)。

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

我将我们的 Web API 应用程序部署到 IIS 并尝试打开和关闭连接:

 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:

在我的本地机器上它很好,但在这台服务器上它在尝试初始化 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

“Oracle.DataAccess.Client.OracleConnection”的类型初始值设定项引发异常。---> Oracle.DataAccess.Client.OracleException: 提供程序与 Oracle 客户端版本不兼容

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.

我已经在服务器上安装了 Oracle 客户端 11.2(32 位),我可以看到在 GAC (c:\windows\assembly) 中,Oracle.DataAccess 程序集安装在 32 位处理器架构中。它在我们的一台服务器上运行良好,但在这台服务器上运行良好。

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

在 IIS 中,我也在应用程序池上设置了“启用 32 位应用程序”。

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

如何修复?到目前为止,我已经花了 10 多个小时尝试不同的事情:(

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

理想情况下,我希望能够使用 Oracle.DataAccess.dll 而无需在服务器上安装 Oracle 客户端。

回答by Dmitry Bychenko

Oracle.DataProvider version 2.102.2.20decrypted

Oracle.DataProvider 版本2.102.2.20解密

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

2: .Net 版本(.Net 1 - 1.1 可以是 1,2 - 3.5 可以是 2,4 - 4.5 可以是 4)

102:甲骨文版本:甲骨文10.2

2.20:Oracle数据访问版本

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

  1. .Net 版本(不应高于您的 .Net 编译器)

  2. Oracle 客户端版本(不应超过 Oracle Client 版本)

  3. Oracle 客户端和 Oracle.DataProvider 都是 64 位或 Oracle.DataProvider 是 32 位,而 Oracle 客户端是 32 位或支持传统 32 位模式

回答by Abdallah

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.
  • PATH 使用 Oracle dll 位置更新:\product\12.1.0\client_1\bin 和 \product\12.1.0\client_1
  • 重新启动服务器。
  • 为 IIS 中的应用程序池启用 32 位。

回答by David Zambrano

you can install Oracle.ManagedDataAccess using Package Manager Console nuget

您可以使用包管理器控制台nuget安装Oracle.ManagedDataAccess

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.

ODP.NET, Managed Driver 是一个 100% 原生的 .NET 代码驱动程序。无需安装额外的 Oracle 客户端软件即可连接到 Oracle 数据库。

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