c# - 如何修复 "The provider is not compatible with the version of Oracle client"?

标签 c# asp.net oracle data-access

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

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

在我的本地机器上没问题,但在这台服务器上尝试初始化 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 客户端 11.2(32 位),我可以看到在 GAC (c:\windows\assembly) 中,Oracle.DataAccess 程序集安装在 32 位处理器架构中。它在我们的一台服务器上运行良好,但在这台服务器上运行不正常。

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

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

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

最佳答案

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

Pm> Install-Package Oracle.ManagedDataAccess

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

更新代码

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

关于c# - 如何修复 "The provider is not compatible with the version of Oracle client"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17425538/

相关文章:

c# - 具有静态工厂方法的 AutoMapper

带有 Entity Framework 4 的 ASP.NET MVC2 - 存储库中的 AsEnumerable() 或 ToList()?

sql - 如何从 Oracle CSV 导出中删除注释行?

mysql - 内部联接查询和接收重复值的问题

c# - 以编程方式设置 closereason

c# - 正则表达式替换可能会或可能不会被引用的字符串

c# - 创建一个类以在运行时实现接口(interface)(如代理类)

c# - 在 C# 中从 url(仅第一个根目录值)获取第一部分

asp.net - 将网站添加到本地主机上的 IIS

oracle - 如何确定 PL/SQL 语句中的行/值抛出错误?