C# Oracle.DataAccess 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9674126/
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-09 08:24:31  来源:igfitidea点击:

Oracle.DataAccess Error

c#asp.netoracledll

提问by Baxter

I have an asp.net / C# web application running in a Windows environment. The project builds fine and runs perfectly on my local machine's VB.net development server.

我有一个在 Windows 环境中运行的 asp.net/C# web 应用程序。该项目构建良好并在我本地机器的 VB.net 开发服务器上完美运行。

However, when I publish to the real application server I receive the following error message:

但是,当我发布到真正的应用程序服务器时,我收到以下错误消息:

[OracleException (0x80004005): The provider is not compatible with the version of Oracle client] [TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.]

[OracleException (0x80004005): The provider is not compatible with the version of Oracle client] [TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' 引发异常。]

There is a version of this application currently up and running just fine, I am testing on the live server in a different directory. I even tried snagging the Oracle.DataAccess .dll from the working application but still get the same error message.

此应用程序的一个版本当前已启动并运行良好,我正在不同目录中的实时服务器上进行测试。我什至尝试从工作应用程序中获取 Oracle.DataAccess .dll,但仍然收到相同的错误消息。

采纳答案by ntziolis

First off: The Oracle client/provider is a mess. And that goes for both the MS one (depreciated anyway) as well as the Oracle one.

首先:Oracle 客户端/提供程序一团糟。这适用于 MS(无论如何都会贬值)和 Oracle 的。

In order to connect to an Oracle DB via the ODP.NET provider three things need to be setup properly:

为了通过 ODP.NET 提供程序连接到 Oracle DB,需要正确设置三件事:

  • Oracle client needs to be setup properly ( has nothing to do with the .NET provider, this referring to the installed oracle client usually in c:\oracle)
  • The ODP.NET provider needs to be compatible with the installed Oracle client
  • The architecture of client and provider and your application need to match, you cannot use the 64bit client with an x86 provider/application and vise versa
  • 需要正确设置 Oracle 客户端(与 .NET 提供程序无关,这是指通常在 c:\oracle 中安装的 oracle 客户端)
  • ODP.NET 提供程序需要与安装的 Oracle 客户端兼容
  • 客户端和提供程序的架构需要与您的应用程序匹配,您不能将 64 位客户端与 x86 提供程序/应用程序一起使用,反之亦然

Usually the best is to have the newest version of both. But if you want to get rid of this issue once and for all use a third party oracle .NET provider.

通常最好是拥有两者的最新版本。但是,如果您想一劳永逸地摆脱这个问题,请使用第三方 oracle .NET 提供程序。

UPDATE

更新

One of the better ones is from DataDirect (no affiliation):
http://www.datadirect.com/products/net/net-for-oracle/index.html

较好的一个来自 DataDirect(无附属关系):http:
//www.datadirect.com/products/net/net-for-oracle/index.html

It's not just installation (no oracle client necessary), but it's also faster, fully managed, x64 and general support is a way better than what you get with the ODP.NET one. It will cost you though.

它不仅是安装(不需要 oracle 客户端),而且速度更快、完全托管、x64 和一般支持比 ODP.NET 更好。但这会花费你。

The DevArt one is pretty decent as well (and much much cheaper):
http://www.devart.com/dotconnect/oracle/

DevArt 也很不错(而且便宜得多):http:
//www.devart.com/dotconnect/oracle/

We decided for the DataDirect for extensibility reasons, this should not be relevant to you however.

出于可扩展性的原因,我们决定使用 DataDirect,但这与您无关。

Here you can find a good compilation of third parties that build .NET providers, not limited to oracle though:
http://msdn.microsoft.com/en-us/data/dd363565

在这里您可以找到构建 .NET 提供程序的第三方的良好汇编,但不仅限于 oracle:http:
//msdn.microsoft.com/en-us/data/dd363565

回答by 3oon

I came across the same scenario before

我之前遇到过同样的场景

Reading this may help you some how ODAC Oracle for .NET

阅读本文可能会帮助您了解ODAC Oracle for .NET

about your problem in your server you have to install the whole ODAC Client from oracle

关于您服务器中的问题,您必须从 oracle 安装整个 ODAC 客户端

the latest version now is 4.xx

现在的最新版本是 4.xx

i have installed it and everything works like charm

我已经安装了它,一切都像魅力一样

hope this helps :)

希望这可以帮助 :)

Take Care

小心

回答by Baxter

I was able to solve this by searching for Oracle.DataAccess.dll on the prod server. So instead of trying to build/deploy the project with the Oracle.DataAccess.dll from my development environment, I copied the .dll down from the prod server oracle client directory and included that as a reference instead. I also set the .dll properties "Copy Local = true" and "Specific Version" = true. So it looks like there is a mismatch between the oracle client version on my dev server and the prod server.

我能够通过在 prod 服务器上搜索 Oracle.DataAccess.dll 来解决这个问题。因此,我没有尝试使用我的开发环境中的 Oracle.DataAccess.dll 构建/部署项目,而是从 prod 服务器 oracle 客户端目录中复制了 .dll 并将其包含为参考。我还设置了 .dll 属性“Copy Local = true”和“Specific Version” = true。所以看起来我的开发服务器和生产服务器上的 oracle 客户端版本不匹配。

回答by Erdnando

Equals, with Oracle.DataAccess.dll    Works!!!!
//using Oracle.DataAccess.Client

object pdf = null;

var queryString =@"SELECT PDF  FROM DIGITAL  WHERE ID_DIGITAL=1001" ;  //example
var ctx = new Entities();
var entityConn = ctx.Connection as EntityConnection;

if (entityConn != null)
{
var dbConn = entityConn.StoreConnection as OracleConnection;
dbConn.Open();

var cmd = new OracleCommand(queryString, dbConn);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
pdf = reader[0];
}
}
dbConn.Close();
}
return pdf;

回答by Serinus

In addition to the other suggestions, just try running Visual Studio as administrator.

除了其他建议之外,只需尝试以管理员身份运行 Visual Studio。

I spent a lot of time messing around with the GAC and various versions of the Oracle.DataAccess.dll, and in the end just running VS as administrator got it to run.

我花了很多时间来处理 GAC 和 Oracle.DataAccess.dll 的各种版本,最后只是以管理员身份运行 VS 让它运行。