提供者与Oracle客户端版本不兼容

发布于 2024-07-16 06:03:37 字数 1872 浏览 12 评论 0原文

我尝试在 ASP.net 项目上使用 Oracle ODP.NET 11g (11.1.0.6.20) Instant Client 作为数据提供程序,但是当我运行我收到一条“提供程序与 Oracle 客户端版本不兼容”错误消息。 任何帮助,将不胜感激。

我在 Visual Studio 2005 中引用了数据提供程序,后面的代码如下所示:

using Oracle.DataAccess.Client;
..

OracleConnection oOracleConn = new OracleConnection();
oOracleConn.ConnectionString =
    "Data Source=MyOracleServerName;" +
    "Integrated Security=SSPI";
oOracleConn.Open();

//Do Something

oOracleConn.Close();

页面的错误如下所示:

Exception Details: Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client

Source Error: 
Line 21: 
Line 22: 
Line 23:             OracleConnection oOracleConn = new OracleConnection();
Line 24:             oOracleConn.ConnectionString =
Line 25:                 "Data Source=MyOracleServerName;" +

[OracleException (0x80004005): The provider is not compatible with the version of Oracle client]
   Oracle.DataAccess.Client.OracleInit.Initialize() +494
   Oracle.DataAccess.Client.OracleConnection..cctor() +483

Stack Trace: 
[TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.]
   Oracle.DataAccess.Client.OracleConnection..ctor() +0
   Boeing.IVX.Web.RoyTesting.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\CE218C\Desktop\IVX.Net\Web\IVX\RoyTesting.aspx.cs:23
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

I'm trying to use the Oracle ODP.NET 11g (11.1.0.6.20) Instant Client on my ASP.net project as a Data Provider but when I run the aspx page I get a "The provider is not compatible with the version of Oracle client" error message. Any help would be appreciated.

I've referenced the Data Provider in Visual Studio 2005 and the code behind looks like this:

using Oracle.DataAccess.Client;
..

OracleConnection oOracleConn = new OracleConnection();
oOracleConn.ConnectionString =
    "Data Source=MyOracleServerName;" +
    "Integrated Security=SSPI";
oOracleConn.Open();

//Do Something

oOracleConn.Close();

The error for the page looks like this:

Exception Details: Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client

Source Error: 
Line 21: 
Line 22: 
Line 23:             OracleConnection oOracleConn = new OracleConnection();
Line 24:             oOracleConn.ConnectionString =
Line 25:                 "Data Source=MyOracleServerName;" +

[OracleException (0x80004005): The provider is not compatible with the version of Oracle client]
   Oracle.DataAccess.Client.OracleInit.Initialize() +494
   Oracle.DataAccess.Client.OracleConnection..cctor() +483

Stack Trace: 
[TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.]
   Oracle.DataAccess.Client.OracleConnection..ctor() +0
   Boeing.IVX.Web.RoyTesting.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\CE218C\Desktop\IVX.Net\Web\IVX\RoyTesting.aspx.cs:23
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(28

那小子欠揍 2024-07-23 06:03:37

我一直在进一步研究这个问题,您只需从同一下载版本的 ODP.Net 中获取所有适当的 DLL,并将它们放在与您的 Exe 文件相同的文件夹中,因为 ODP.Net 很挑剔不混合版本号。

我已经在这里解释了如何执行此操作: http ://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c
不过,要点如下:

  • 下载 ODP.Net
  • 解压文件
  • 解压其中的所有 JAR
  • 获取刚刚解压的这些 dll:
    • oci.dll(从“oci.dll.dbl”重命名)
    • Oracle.DataAccess.dll
    • oraociicus11.dll
    • OraOps11w.dll
    • orannzsbb11.dll
    • oraocci11.dll
    • ociw32.dll(从“ociw32.dll.dbl”重命名)
  • 把所有 DLL 与 C# 可执行文件位于同一文件夹中

I've been looking into this problem further, and you simply need to grab all the appropriate DLL's from the same downloaded version of ODP.Net and put them in the same folder as your Exe file, because ODP.Net is fussy about not mixing version numbers.

I've explained how to do this here: http://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c
Here's the gist of it though:

  • Download ODP.Net
  • Unzip the file
  • Unzip all the JAR's in it
  • Grab these dll's that were just unzipped:
    • oci.dll (renamed from 'oci.dll.dbl')
    • Oracle.DataAccess.dll
    • oraociicus11.dll
    • OraOps11w.dll
    • orannzsbb11.dll
    • oraocci11.dll
    • ociw32.dll (renamed from 'ociw32.dll.dbl')
  • Put all the DLLs in the same folder as your C# Executable
鹊巢 2024-07-23 06:03:37

您应该“忽略”这里针对初学者的所有 x86/x64 讨论,而是尝试 ODP.NET 托管驱动程序(如果您使用的是 .Net v4+):

https://www.nuget.org/packages/Oracle.ManagedDataAccess/

https://www.nuget.org/packages/Oracle.ManagedDataAccess.EntityFramework/

Oracle ODP.net 托管与非托管驱动程序

避免所有“非托管”什么 DLL 什么架构问题! :D(关于 Oracle 时间)。

NuGet 包(也适用于 11g):

< img src="https://i.sstatic.net/i7l0w.png" alt="在此处输入图像描述">

旧/手动方法:

有关如何转换为使用托管库的信息:

  • 首先,这里是托管非托管的精彩代码比较:http://docs.oracle.com/cd/E51173_01/win。 122/e17732/intro005.htm#ODPNT148
  • 确保您已下载ODP.NET,仅限托管驱动程序 Xcopy 版本
  • 从下载的 zip 文件中,复制并粘贴到您的项目目录中:
    • Oracle.ManagedDataAccessDTC.dll
    • Oracle.ManagedDataAccess.dll
  • 添加对 Oracle.ManagedDataAccess.dll 的引用
  • 确保您的 exe 已发布 (添加到 VS2010 中的应用程序文件夹)以及两个 dll

You should "ignore" all the x86/x64 talk here for starters and instead try the ODP.NET Managed Driver (if you are using .Net v4+):

https://www.nuget.org/packages/Oracle.ManagedDataAccess/

https://www.nuget.org/packages/Oracle.ManagedDataAccess.EntityFramework/

Oracle ODP.net Managed vs Unmanaged Driver

Avoid all the "unmanaged" what DLL what architecture issues! :D (about time Oracle).

The NuGet package (also works for 11g):

enter image description here

The old / manual method:

For info on how to convert to using the managed libraries:

  • First, here is a great code comparison of managed vs unmanaged: http://docs.oracle.com/cd/E51173_01/win.122/e17732/intro005.htm#ODPNT148
  • Ensure you have downloaded the ODP.NET, Managed Driver Xcopy version only
  • From the downloaded zip file, copy and paste into your project directory:
    • Oracle.ManagedDataAccessDTC.dll
    • Oracle.ManagedDataAccess.dll
  • Add a reference to Oracle.ManagedDataAccess.dll
  • Ensure your exe is released (added to Application Folder in VS2010) with both dlls
你又不是我 2024-07-23 06:03:37

我只安装了 Oracle Data Provider for .NET 2.0 (11.1.0.6.20),而没有安装 Oracle Instant Client (11.1.0.6.0)

我刚刚安装了它,错误消失了!

I only installed the Oracle Data Provider for .NET 2.0 (11.1.0.6.20) and I did not install the Oracle Instant Client (11.1.0.6.0).

I just installed it and the error disappeared!

梦初启 2024-07-23 06:03:37

这可能是由于针对 32 位 Oracle 客户端运行 64 位 .NET 运行时造成的。 如果您的服务器运行的是 64 位应用程序,则可能会发生这种情况。 它将使用 64 位运行时运行 .NET 应用程序。 您可以在 VS 中设置项目的 CPU 标志以在 32 位运行时运行。

This can be caused by running a 64bit .NET runtime against a 32bit Oracle client. This can happen if your server you are running the app on it 64 bit. It will run the .NET app with the 64bit runtime. You can set the CPU flag on your project in VS to run in the 32bit runtime.

面如桃花 2024-07-23 06:03:37

让我们做一些总结:

错误消息“提供程序与Oracle客户端的版本不兼容”可能由多种原因引起。 同时,错误消息可能有不同的风格,例如“未将对象引用设置为对象的实例。”“无法加载文件或程序集“Oracle.DataAccess”或其中之一它的依赖项”

  • 您没有安装 Oracle 客户端。 在这种情况下,错误消息确实具有误导性。

Oracle Data Provider for .NET(ODP.NET,即文件 Oracle.DataAccess.dll)不包含在 Oracle Instant Client 中,必须单独安装(从 32 位 Oracle 数据访问组件 (ODAC) 64 位 Oracle 数据访问组件 (ODAC) 下载),否则您必须在 Oracle Universal Installer (OUI) 中选择相应的选项。

请注意,当安装 Oracle Data Provider >= 12.1 时,该提供程序不会自动注册到 GAC 中。 如果需要,您必须手动注册,请参阅 Oracle Doc 2272241.1

  • ODP.NET 的版本与安装的 Oracle 客户端版本不匹配。 即使是次要版本号也必须检查! 例如,Oracle.DataAccess.dll 版本 4.112.3.0 与 Oracle 客户端 11.2.0.4 不兼容。 仔细检查ODP.NET和Oracle Client的版本。 您可以在 oraociei*.dllsigcheck code> 和/或 OraOps*w.dll 来获取 Oracle 客户端的版本。

    注意不同的编号方案。 文件版本 4.112.3.0 表示:.NET Framework 版本 4、Oracle 版本 11.2.0.3.x

    ODP.NET 版本有“1.x”、“2.x”和“4.x”。 这些数字与 Microsoft .NET Framework 版本 1.0.3705/1.1.4322、2.0.50727 和 4.0.30319 相关。 版本“1.x”在 Oracle Client 11.1 之前可用。 版本“4.x”随 Oracle Client 11.2 一起引入

  • ODP.NET 的体系结构(32 位或 64 位)与您的应用程序体系结构不匹配。 32 位应用程序仅适用于 32 位 Oracle Client/ODP.NET,64 位应用程序则需要 64 位 Oracle Client/ODP.NET。 (除非您使用ODP.NET托管驱动程序

  • .NET Framework 版本不匹配。 例如,如果您使用 Target .NET Framework 2.0 编译应用程序,则无法使用 ODP.NET 版本 4.x。 .NET Framework 目标版本必须等于或高于 ODP.NET 版本。

  • 您的开发计算机上的Oracle.DataAccess.dll版本(即编译时加载的版本)高于目标计算机上的版本。

  • 请注意,Oracle.DataAccess.dll 可能会从 GAC< 加载/a> 默认情况下优先于任何本地提供的文件。


  • 较新版本的 ODP.NET 需要更高的 Microsoft .NET Framework 版本。 例如,ODP.NET 版本 21.4 需要 .NET Framework 4.8。 检查您版本的“.NET 数据提供程序开发人员指南”中的系统要求。

解决方案

  • 考虑使用ODP.NET托管驱动程序,它可以从Oracle页面下载:64 位 Oracle 数据访问组件 (ODAC) 下载
    您只需将 Oracle.ManagedDataAccess.dll 文件复制到应用程序目录即可,无需其他任何操作。 它适用于 32 位和 64 位。

  • 在您的*.csproj中,分别。 *.vbproj 编辑对 ODP.NET 的引用,如下所示:

     <参考 Include="Oracle.DataAccess"> 
         <特定版本>假 
         <私人>假 
        
      

不需要 Version=...processorArchitecture=... 等属性。 您的应用程序将根据所选体系结构和目标 .NET 框架加载正确的 Oracle.DataAccess.dll(前提是安装正确)
-> 未 100% 验证

  • 如果您不知道目标计算机上 Oracle 客户端的版本(例如,它可能是您客户的计算机):转到上述下载页面并下载最低版本的XCopyOracle.DataAccess.dll 文件复制到本地计算机。 在您的 VS 项目中引用此(很可能已过时)DLL。 此 DLL 的版本是您的应用程序可以使用的 ODP.NET 的最低版本。 当您运行应用程序时,GAC 中的发布者策略将重定向到实际安装的版本。


  • 我认为将单个 DLL 复制到某些文件夹并不是明智的做法。 它可能在“裸”机器上运行,但如果您的目标机器安装了任何 Oracle 产品,则版本不匹配的风险很高。 从您的计算机中卸载所有 Oracle 产品并进行全新安装。 看看如何卸载/完全删除Oracle 11g(客户端)? 它是为了获得一台真正干净的机器。

  • 如果您必须同时使用 32 位和 64 位应用程序,请按照以下说明在一台计算机上安装两个版本:

假设:Oracle Home 名为 OraClient11g_home1,客户端版本为 11gR2。

  • 可以选择删除任何已安装的 Oracle 客户端

  • 下载并安装 Oracle x86 客户端,例如安装到 C:\Oracle\11.2\Client_x86

  • 下载 Oracle x64 客户端并安装到不同文件夹,例如安装到 C:\Oracle\11.2 \Client_x64

  • 打开命令行工具,转到文件夹 %WINDIR%\System32,通常 C :\Windows\System32 并创建到文件夹 C:\Oracle\11.2\Client_x64 的符号链接 ora112(见下文)

  • 更改为文件夹 %WINDIR%\SysWOW64,通常为 C:\Windows\SysWOW64 并创建符号链接 ora112 到文件夹 C:\Oracle\11.2\Client_x86,(见下文)

  • 修改 PATH 环境变量,替换所有条目,如 C:\Oracle\11.2\Client_x86C:\ Oracle\11.2\Client_x64 by C:\Windows\System32\ora112,各自的 \bin 子文件夹。 注意:C:\Windows\SysWOW64\ora112 不得位于 PATH 环境中。

  • 如果需要,将您的 ORACLE_HOME 环境变量设置为 C:\Windows\System32\ora112

  • 打开注册表编辑器。 将注册表值 HKLM\Software\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME 设置为 C:\Windows\System32\ora112

  • 设置注册表值 HKLM\Software\Wow6432Node\ ORACLE\KEY_OraClient11g_home1\ORACLE_HOMEC:\Windows\System32\ora112(不是 C:\Windows\SysWOW64\ora112

  • 你完成了! 现在您可以无缝地一起使用 x86 和 x64 Oracle 客户端,即 x86 应用程序将加载 x86 库,x64 应用程序加载 x64 库,而无需对系统进行任何进一步修改。

创建符号链接的命令:

cd C:\Windows\System32
mklink /d ora112 C:\Oracle\11.2\Client_x64
cd C:\Windows\SysWOW64
mklink /d ora112 C:\Oracle\11.2\Client_x86

一些注意事项:

  • 两个符号链接必须具有相同的名称,例如 ora112

  • 如果您想随后手动安装 ODP.NET,请注意选择适当的文件夹进行安装。

  • 尽管名称不同,文件夹 C:\Windows\System32 包含 x64 库,而 C:\Windows\SysWOW64 包含 x86(32 位)库。 不要混淆。

  • 也许将您的 TNS_ADMIN 环境变量(分别是注册表中的 TNS_ADMIN 条目)设置为公共位置是一个明智的选择,例如 TNS_ADMIN=C :\Oracle\Common\network

Let's make some kind of summary:

Error message "The provider is not compatible with the version of Oracle client" can be caused by several reasons. Meanwhile the error message can have different flavors, e.g. "Object reference not set to an instance of an object." or "Could not load file or assembly 'Oracle.DataAccess,' or one of its dependencies"

  • You have no Oracle Client installed. In this case the error message is indeed misleading.

Oracle Data Provider for .NET (ODP.NET, i.e. file Oracle.DataAccess.dll) is not included in Oracle Instant Client, it has to be installed separately (download from 32-bit Oracle Data Access Components (ODAC) or 64-bit Oracle Data Access Components (ODAC) Downloads) or you have to select according option in Oracle Universal Installer (OUI).

Note, when installing the Oracle Data Provider >= 12.1, then the provider is not automatically registered into GAC. You have to register it manually if needed, see Oracle Doc 2272241.1.

  • The version of ODP.NET does not match installed version of Oracle Client. You have to check even the minor version number! For example, Oracle.DataAccess.dll Version 4.112.3.0 is not compatible with Oracle Client 11.2.0.4. Check versions of ODP.NET and Oracle Client carefully. You can use sigcheck on oraociei*.dll and/or OraOps*w.dll to get version of Oracle Client.

    Be aware of different numbering scheme. File version 4.112.3.0 means: .NET Framework Version 4, Oracle Release 11.2.0.3.x.

    There are ODP.NET version "1.x", "2.x" and "4.x". These numbers are related to Microsoft .NET Framework versions 1.0.3705/1.1.4322, 2.0.50727 and 4.0.30319. Version "1.x" was available until Oracle Client 11.1. Version "4.x" was introduced with Oracle Client 11.2

  • The architecture (32bit or 64bit) of ODP.NET does not match your application architecture. A 32bit application works only with 32bit Oracle Client/ODP.NET respectively a 64bit application requires 64bit Oracle Client/ODP.NET. (Unless you use ODP.NET Managed Driver)

  • The .NET Framework version do not match. For example, if you compile your application with Target .NET Framework 2.0 then you cannot use ODP.NET version 4.x. The .NET Framework target version must be equal or higher than version of ODP.NET.

  • The version of Oracle.DataAccess.dll on your development machine (i.e. the version which is loaded while compiling) is higher than the version on the target machine.

  • Be aware that Oracle.DataAccess.dll might be loaded from GAC which by default takes precedence over any locally provided file.

  • Newer release of ODP.NET requires higher Microsoft .NET Framework version. For example ODP.NET version 21.4 requires .NET Framework 4.8. Check the System Requirements in the "Data Provider for .NET Developer's Guide" of your release.

Solutions

  • Consider to use the ODP.NET Managed Driver, it can be downloaded from Oracle page: 64-bit Oracle Data Access Components (ODAC) Downloads.
    There you only have to copy Oracle.ManagedDataAccess.dll file to your application directory, nothing else is required. It works for both 32bit and 64bit.

  • In your *.csproj, resp. *.vbproj edit your reference to ODP.NET like this:

     <Reference Include="Oracle.DataAccess">
       <SpecificVersion>False</SpecificVersion>
       <Private>False</Private>
     </Reference>
    

Attributes like Version=... or processorArchitecture=... are not required. Your application will load the correct Oracle.DataAccess.dll depending on selected architecture and target .NET framework (provided that it is installed properly)
-> not 100% verified

  • In case you do not know the version of Oracle Client on target machine (e.g. it might be the machine of your customer): Go to the download page mentioned above and download the least XCopy version of Oracle Data Access Components. Extract the zip and copy just the Oracle.DataAccess.dll file to your local machine. In your VS project make a reference to this (most likely outdated) DLL. The version of this DLL is the least version of ODP.NET your application will work with. When you run your application then the Publisher Policy in GAC will redirect to actually installed version.

  • I don't think it is a smart approach to take single DLL's and copy them to certain folders. It may work on a "naked" machine but if your target machine has installed any Oracle products there is a high risk for version mismatch. Uninstall any Oracle products from your machine and make a fresh installation. Have a look at How to uninstall / completely remove Oracle 11g (client)? it order to get a really clean machine.

  • In case you have to work with 32bit and 64bit applications at the same time, follow this instruction to install both versions on one machine:

Assumptions: Oracle Home is called OraClient11g_home1, Client Version is 11gR2.

  • Optionally remove any installed Oracle client

  • Download and install Oracle x86 Client, for example into C:\Oracle\11.2\Client_x86

  • Download and install Oracle x64 Client into different folder, for example to C:\Oracle\11.2\Client_x64

  • Open command line tool, go to folder %WINDIR%\System32, typically C:\Windows\System32 and create a symbolic link ora112 to folder C:\Oracle\11.2\Client_x64 (see below)

  • Change to folder %WINDIR%\SysWOW64, typically C:\Windows\SysWOW64 and create a symbolic link ora112 to folder C:\Oracle\11.2\Client_x86, (see below)

  • Modify the PATH environment variable, replace all entries like C:\Oracle\11.2\Client_x86 and C:\Oracle\11.2\Client_x64 by C:\Windows\System32\ora112, respective their \bin subfolder. Note: C:\Windows\SysWOW64\ora112 must not be in PATH environment.

  • If needed set yor ORACLE_HOME environment variable to C:\Windows\System32\ora112

  • Open your Registry Editor. Set Registry value HKLM\Software\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112

  • Set Registry value HKLM\Software\Wow6432Node\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112 (not C:\Windows\SysWOW64\ora112)

  • You are done! Now you can use x86 and x64 Oracle client seamless together, i.e. an x86 application will load the x86 libraries, an x64 application loads the x64 libraries without any further modification on your system.

Commands to create symbolic links:

cd C:\Windows\System32
mklink /d ora112 C:\Oracle\11.2\Client_x64
cd C:\Windows\SysWOW64
mklink /d ora112 C:\Oracle\11.2\Client_x86

Some notes:

  • Both symbolic links must have the same name, e.g. ora112.

  • In case you want to install ODP.NET manually afterwards, take care to select appropriate folders for installation.

  • Despite of their names folder C:\Windows\System32 contains the x64 libraries, whereas C:\Windows\SysWOW64 contains the x86 (32-bit) libraries. Don't be confused.

  • Maybe it is a wise option to set your TNS_ADMIN environment variable (resp. TNS_ADMIN entries in Registry) to a common location, for example TNS_ADMIN=C:\Oracle\Common\network.

沙沙粒小 2024-07-23 06:03:37

经过几个小时的故障排除,我发现这个问题是由于我的项目 bin 目录中存在 Oracle.DataAccess.dll (v4.0),但运行时还从 GAC 加载 Oracle.DataAccess.dll (v2.x) 引起的。 删除并读取项目引用中的 Oracle.DataAccess 条目解决了我的问题。

这里提到的其他文件在我的情况下似乎没有必要。

更新

“提供程序与 Oracle 客户端的版本不兼容”错误的根本原因(通常)是托管程序集尝试加载与版本不匹配的非托管库。 看来您可以通过在 web.config1

<configuration>
  <oracle.dataaccess.client>
    <settings>
      <add name="DllPath" value="C:\oracle\bin"/>
      <!-- ... -->
    </settings>
  </oracle.dataaccess.client>
</configuration>

After several hours of troubleshooting, I found this issue to be caused by having Oracle.DataAccess.dll (v4.0) in my projects bin directory, but the runtime also loading Oracle.DataAccess.dll (v2.x) from the GAC. Removing and readding the Oracle.DataAccess entry in the project references solved the problem for me.

The other files mentioned here did not appear to be necessary in my situation.

UPDATE

The root cause of the "The provider is not compatible with the version of Oracle client" error is (generally) that the managed assembly is attempting to load unmanaged libraries which do not match versions. It appears you can force the Oracle driver to use the correct libraries by specifying the library path in the web.config1

<configuration>
  <oracle.dataaccess.client>
    <settings>
      <add name="DllPath" value="C:\oracle\bin"/>
      <!-- ... -->
    </settings>
  </oracle.dataaccess.client>
</configuration>
诗笺 2024-07-23 06:03:37

在目标计算机上安装 ODP.Net,它应该可以解决问题...复制 dll 看起来不是一个好主意...

install ODP.Net on the target machine and it should solve the issue... copying the dll's does not look a good idea...

层林尽染 2024-07-23 06:03:37

对于 Oracle 11g (11.1.0.7.20),我必须添加以下 dll 和我的 Exe 才能工作。

  1. oci.dll
  2. OraOps11w.dll
  3. oraociicus11.dll(相当大,接近 30mb)
  4. Oracle.DataAccess.dll

For Oracle 11g (11.1.0.7.20) I had to add the following dlls along with my Exe to work.

  1. oci.dll
  2. OraOps11w.dll
  3. oraociicus11.dll (pretty huge close to 30mb)
  4. Oracle.DataAccess.dll
往日 2024-07-23 06:03:37

在我看来,虽然您有带有 Oracle Istant 客户端的 ODP,但 ODP 可能会尝试使用实际的 Oracle 客户端。 您的计算机上是否还安装了标准 Oracle 客户端? 我记得 Oracle 对于同一台机器上的多个客户端非常挑剔。

It would seem to me that though you have ODP with the Oracle Istant Client, the ODP may be trying to use the actual Oracle Client instead. Do you have a standard Oracle client installed on the machine as well? I recall Oracle being quite picky about when it came to multiple clients on the same machine.

皓月长歌 2024-07-23 06:03:37

我有同样的问题,但就我而言,我不能只是将 dll 复制到 bin 文件夹中,然后我只能“重新绑定”程序集版本。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>    
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342" culture="neutral"/>
        <bindingRedirect oldVersion="2.112.2.0" newVersion="2.112.1.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

i have the same problem but in my case i can't just copy the dlls into the bin folder, then i only 'rebind' the assembly version.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>    
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342" culture="neutral"/>
        <bindingRedirect oldVersion="2.112.2.0" newVersion="2.112.1.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
过去的过去 2024-07-23 06:03:37

以下是我为解决这个持续了 3 个小时的问题所做的操作:

  1. 在位于 C:\oracle\product\11.2.0 的 Oracle 主目录下,我有一个名为 client_1< /code> 我之前在其中安装了适用于 Windows 64 位的 ODP.NET 位。

  2. 后来在尝试使用 Visual Studio 2012 调试我的 ASP.NET Web API 应用程序时,我不断收到此错误消息:提供程序与 Oracle 客户端的版本不兼容

  3. 搜索 Google 我发现发生这种情况是因为我使用的是 ODP.NET 64 位。 然后我抓取了适用于 Windows 32 位的 ODP.NET 并安装了它,但我不断收到相同的错误消息。

  4. 解决方案:删除文件夹 client_1 并重新安装 ODP.NET 32 位。 安装程序在某种程度上将 64 位版本与 32 位版本混合在一起。 想想看...

  5. 现在我又高兴了,我可以打开一个新的 OracleConnection。 最后! :)

Here's what I did to solve this problem that persisted for 3 long hours:

  1. Under Oracle home located at C:\oracle\product\11.2.0 I had a folder called client_1 where I had previously installed ODP.NET bits for Windows 64 bits.

  2. Later while trying to debug my ASP.NET Web API app with Visual Studio 2012, I kept getting this error message: The provider is not compatible with the version of Oracle client.

  3. Searching Google I found that this was happening because I was using ODP.NET 64 bits. Then I grabbed ODP.NET for Windows 32 bits and installed it but I kept getting the same error message.

  4. SOLUTION: deleted the folder client_1 and resinstalled ODP.NET 32 bits. Somewhat the installer was mixing bits from the 64 bit version with the 32 bit version. Go figure...

  5. Now I'm happy again and I can open a new OracleConnection. FINALLY! :)

迷爱 2024-07-23 06:03:37

TLDR 版本:

  • 使用 12c 100% 托管提​​供程序反而。
  • 如果必须使用旧的提供程序,则需要将 Oracle.DataAccess.dll 指向正确版本的非托管 Oracle 客户端 Dll。 如果您的计算机上安装了多个 Oracle 客户端,可能只需在应用程序配置中包含“DllPath”配置变量(见下文)即可,但您可能还需要安装一个新的 Oracle 客户端来指向。

完整版本:

首先,让我们确保我们了解旧的非托管提供程序(而不是新的 12c 100% 托管提​​供程序)的组件。 它由两部分组成:

  1. 托管 .net 组件 - Oracle.DataAccess.dll
  2. 非托管(非 .net)客户端

简而言之,Oracle.DataAccess.dll 几乎只是一个包装器,将 .net 指令转换为 ORACLE-NET 指令对于非托管客户端。

也就是说,当您加载 Oracle.DataAccess 时,它会按照一定的顺序尝试查找所需的非托管客户端 dll。 来自 Oracle 文档

Oracle.DataAccess.dll 搜索依赖的非托管 DLL(例如
作为 Oracle 客户端)基于以下顺序:

1.应用程序或可执行文件的目录。

2.由应用程序配置或web.config指定的DllPath设置。

3.由machine.config指定的DllPath设置。

4.Windows注册表指定的DllPath设置。

HKEY_LOCAL_MACHINE\Software\Oracle\ODP.NET\version\DllPath

5.Windows PATH环境变量指定的目录。

因此,在您的情况下,您的应用程序遵循上述过程并找到了一个包含未托管 dll 的路径,这些 dll 相对于您正在使用的 Oracle.DataAccess.dll 程序集来说太旧了。

可能只是该计算机上安装的唯一 Oracle 客户端太旧了。 但是,如果您在计算机上安装了多个客户端,并且首先在不同但较旧的安装中找到了非托管文件,那么这一点就会发挥作用。 如果是后者,简单的做法是在配置中使用 dllPath 配置变量并将其指向正确的 Oracle Home Bin 文件夹:

<configuration>
  <oracle.dataaccess.client> 
    <add key="DllPath" value="c:\oracle\product\1.1.0-xcopy-dep\BIN"/>
  </oracle.dataaccess.client>
</configuration>

如果要安装客户端的全新副本,则 xcopy 版本 是最小的,包含“即时客户端”并指向 DllPath到这个新位置。 但任何 Oracle 客户端安装都可以工作。

但是,如果您想避免所有这些非托管客户端解析问题,请查看是否可以更新您的应用程序以使用 100% 托管提​​供程序 - 它实际上只是一两个托管程序集,而不依赖于非托管文件。

如果 Oracle.DataAccess.dll 安装在您的 bin 目录和 GAC 中,您也可能没有加载您认为的 Oracle.DataAccess.dll,但我认为这种情况不太可能发生。 请参阅 程序集解析过程了解更多信息。

TLDR Version:

  • Use the 12c 100% managed provider instead.
  • If you must use the old provider, you need to point Oracle.DataAccess.dll to the unmanaged Oracle Client Dlls that are of the correct version. If you have multiple Oracle Clients installed on your machine that maybe a simple as including the "DllPath" configuration variable (see below) in you app config, but you may also need to install a new oracle client to point to.

Full version:

First, lets make sure we understand the components of the old unmnaged provider (not the new 12c 100% managed provider). It's made up of two pieces:

  1. the managed .net component - Oracle.DataAccess.dll
  2. the unmanaged (non-.net) client

Simply speaking, Oracle.DataAccess.dll is nearly just a wrapper, translating .net instructions into ORACLE-NET instructions for the unmanaged client.

That said, when you load Oracle.DataAccess there is a order in which it tries to locate the unmanaged client dlls that it needs. From the Oracle Documentation:

The Oracle.DataAccess.dll searches for dependent unmanaged DLLs (such
as Oracle Client) based on the following order:

1.Directory of the application or executable.

2.DllPath setting specified by application config or web.config.

3.DllPath setting specified by machine.config.

4.DllPath setting specified by the Windows Registry.

HKEY_LOCAL_MACHINE\Software\Oracle\ODP.NET\version\DllPath

5.Directories specified by the Windows PATH environment variable.

So in your case, your app followed this process above and found a path that has unmananged dlls that are too old relative to the Oracle.DataAccess.dll assembly that you are using.

It could just be that the only Oracle Client install on that machine is too old. But this comes into play if you have more than one client installed on the machine and the unmananaged files were found first in a different but older installation. If the later, the simple thing to do is use the dllPath configuration variable in your config and point it at the correct Oracle Home Bin folder:

<configuration>
  <oracle.dataaccess.client> 
    <add key="DllPath" value="c:\oracle\product\1.1.0-xcopy-dep\BIN"/>
  </oracle.dataaccess.client>
</configuration>

If you want to install a fresh copy of the client, the xcopy version is the smallest and contains the "instant client" and point the DllPath above to this new location. But any oracle client install will work.

But if you want to avoid all this unmanaged client resolution stuff, see if you can update your app to use the 100% managed provider instead - it truely is just one or two managed assemblies,without any dependency on unmananged files.

Its also possible that you aren't loading the Oracle.DataAccess.dll that you think you are if it is installed in both your bin directory and your GAC, but I think that is the less likely senario. See the assembly resolution process for more information.

茶底世界 2024-07-23 06:03:37

IIS/IWAM用户是否有Oracle目录的权限? 您可以使用其他应用程序(例如 Excel 或 Access)连接到此数据源吗?

Does the IIS/IWAM user have permissions on the Oracle directory? Can you connect to this data source using another app, such as Excel or Access?

忱杏 2024-07-23 06:03:37

我有同样的问题。 编译应用程序后,我删除了(并且忘记了我已经删除了)oraociei11.dll。 并且在尝试执行时出现此错误。 因此,当它找不到 oraociei11.dll 的 dll 时,它会显示此错误。 可能还有其他情况会出现此错误,但这似乎是其中之一。

I had the exact same problem. I deleted (and forgot that I had deleted) oraociei11.dll after compiling the application. And it was giving this error while trying to execute. So when it cant find the dll that oraociei11.dll, it shows this error. There may be other cases when it gives this error, but this seems to be one of them.

野却迷人 2024-07-23 06:03:37

还要查找 IIS 应用程序池启用 32 位 true 或 false 标志,当您看到此消息时,一些 Oracle 论坛指示我这样做!

Also look for IIS Application pool Enable 32-bit true or false flag, when you see this message, some oracle forum directed me for this!

自在安然 2024-07-23 06:03:37

对于仍然遇到此问题的任何人:根据这篇文章

http://oradim.blogspot.com/2009/09/odpnet-provider-is-not-company-with.html

我发现我的服务器缺少 Microsoft C++ Visual Runtime Library - 我已经安装了它我的开发机器因为安装了 Visual Studio。 我从这里下载并安装了该库的(当前)最新版本:

http://www.microsoft.com/en-us/download/details.aspx?id=13523

运行设置,C# 的 oracle 调用成功了!

For anyone still having this problem: based on this article

http://oradim.blogspot.com/2009/09/odpnet-provider-is-not-compatible-with.html

I found out that my server was missing the Microsoft C++ Visual Runtime Library - I had it on my dev machine because of the Visual Studio installed. I downloaded and installed the (currently) most recent version of the library from here:

http://www.microsoft.com/en-us/download/details.aspx?id=13523

Ran the setup and the oracle call from C# made it!

负佳期 2024-07-23 06:03:37

我没有走上获取新 DLL 的道路。 我们有很多现有的项目运行得很好,只有我的新项目让我头疼,所以我决定尝试其他东西。

我的项目使用的是内部开发的Internal.dll,它依赖于Oracle.DataAccess.dll v4.112.3.0。 由于某种原因,发布时,Visual Studio 始终上传 v4.121.0.0,即使没有在任何配置文件中明确指定。 这就是我收到错误的原因。

所以我所做的是:

  1. 将 Internal.dll 从成功运行的项目之一复制到我网站的 /bin (只是为了安全起见)。
  2. 将 Oracle.DataAccess.dll 从成功运行的项目之一复制到我网站的 /bin
  3. 从我的网站添加对它们的引用。
  4. 最后,Oracle.DataAccess 参考出现在 myWebSite.csproj 中,但显示了错误的版本:v4.121.0.0 而不是 v4.112.3.0代码>.
  5. 我手动更改了 myWebSite.csproj 中的引用,因此现在显示为:

     
        <特定版本>假 
        bin\Oracle.DataAccess.dll 
        
      

I didn't go down the road of getting new DLL's. We had a bunch of existing projects that work perfectly fine and it was only my new project that was giving me headache so I decided to try something else.

My project was using an internally developed Internal.dll that depended on Oracle.DataAccess.dll v4.112.3.0. For some reason, when publishing, Visual Studio always uploaded v4.121.0.0, even though it wasn't explicitly specified in any of the config files. That's why I was getting an error.

So what I did was:

  1. Copied Internal.dll from one of the successfully running projects to my web site's /bin (just to be on the safe side).
  2. Copied Oracle.DataAccess.dll from one of the successfully running projects to my web site's /bin.
  3. Add Reference to both of them from my web site.
  4. Finally Oracle.DataAccess reference showed up in myWebSite.csproj, but it showed the wrong version: v4.121.0.0 instead of v4.112.3.0.
  5. I manually changed the reference in myWebSite.csproj, so it now read:

    <Reference Include="Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>bin\Oracle.DataAccess.dll</HintPath>
    </Reference> 
    
我早已燃尽 2024-07-23 06:03:37

如果您有多个 Oracle 客户端,或者有时引用不同版本,则在使用非托管 Oracle 引用时可能会发生此问题
有两种方法可以解决这个问题:

  1. 第一个也是快速的解决方案是删除非托管引用并使用 NuGet 中的托管引用,请在使用此选项之前查看此内容 ODP.NET 托管驱动程序和非托管驱动程序之间的差异

  2. 第二个解决方案是修复项目非托管目标版本,如下所示:

  • 首先检查 oracle 项目参考版本(来自项目引用/(依赖项 > 程序集) > Oracle.DataAccess 右键单击​​ > 属性):

    输入图片此处描述

    输入图片此处描述

然后检查 oracle GAC 版本

  • 从 run (Win+R) "%windir%\Microsoft.NET\ assembly 获取 gac ”
    输入图片此处描述

  • 检查与您的项目平台匹配的平台

    输入图片此处描述

  • 检查您的目标平台(右键单击您的项目>属性)

    输入图片此处描述

  • 从 gac 文件夹搜索到 Oracle.DataAccess

    在此处输入图像描述

  • 右键单击 Oracle.DataAccess > 属性> 详细信息并检查版本

    在此处输入图像描述

  • 如果您发现版本不同,这是一个问题,要解决它,我们需要重定向程序集版本(在启动项目中转到配置文件并添加以下部分)

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.121.2.0" />
      </dependentAssembly>
</assemblyBinding>

如下所示
输入图片这里的描述

oldVersion :应该覆盖你的项目版本
新版本:广汽版本
publicKeyToken :来自 GAC

输入图片此处描述

This issue could by happen while using unmanaged oracle reference if you have more than one oracle client , or sometimes if you reference different version
There is two way to solve it :

  1. First and fast solution is to remove unmanaged reference and use the managed one from NuGet see this before to go with this option Differences between the ODP.NET Managed Driver and Unmanaged Driver

  2. Second solution is to fix project unmanaged target version like the below :

  • First Check oracle project reference version (from project references/(dependencies > assemblies ) > Oracle.DataAccess right click > properties):

    enter image description here

    enter image description here

Then check oracle GAC version

  • got to gac from run (Win+R) "%windir%\Microsoft.NET\assembly"
    enter image description here

  • Check the platform that matches with you project platform

    enter image description here

  • to check you target platform (right click on your project > properties)

    enter image description here

  • From gac folder search to Oracle.DataAccess

    enter image description here

  • Right Click on Oracle.DataAccess > properties > details and check version

    enter image description here

  • if you notice the versions are different this is an the issue and to fix it we need to redirect assembly version (in startup project go to config file and add the below section )

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.121.2.0" />
      </dependentAssembly>
</assemblyBinding>

like this
enter image description here

oldVersion : should be cover your project version
newVersion : GAC version
publicKeyToken : From GAC

enter image description here

波浪屿的海角声 2024-07-23 06:03:37

我们遇到了同样的问题,因为网络共享上的 Oracle.Data.dll 程序集已由我们的 DBA 更新。 从项目中删除引用,然后再次添加即可解决问题。

We had the same problem, because the Oracle.Data.dll assembly on a network share was updated by our DBA's. Removing the reference from the project, and adding it again solved the problem.

哥,最终变帅啦 2024-07-23 06:03:37

只需两步即可解决此问题。

  1. 转到应用程序池的高级设置并将“启用 32 位应用程序”标志设置为 True。
  2. 确保 Bin 中的所有 Dll 现在都是 32 位版本...

祝你好运。

Just two steps to solve this issue.

  1. go to advance setting of application pool and set 'Enable 32 bit Application' flag to True.
  2. Make sure all Dlls in your Bin is 32 bit version now...

best of luck.

满地尘埃落定 2024-07-23 06:03:37

最近,我必须处理一个较旧的项目,其中解决方案和所有包含的项目都针对 x32 平台。 我一直尝试在所有位置复制 Oracle.DataAccess.dll 和所有其他建议的 Oracle 文件,但每次都碰壁。 最后,头部的灯泡亮了(8 小时后:)),并要求检查已安装的 ODAC 组件及其平台。 我已经安装了所有 64 位 (x64) ODAC 客户端,但没有安装 32 位 (x32)。 安装32位ODAC后问题就消失了。

如何检查已安装的 ODAC 的版本:查看文件夹 C:\Windows\Assembly。 “处理器架构”属性将告知平台已安装的 ODAC。

八小时对于灯泡点亮来说是很长的时间。 难怪我总是要努力工作:)。

Recently I had to work on an older project where the solution and all contained projects were targeted to x32 platform. I kept on trying to copy Oracle.DataAccess.dll and all other suggested Oracle files on all the places, but hit the wall every time. Finally the bulb in the head lit up (after 8 hours :)), and asked to check for the installed ODAC assemblies and their platform. I had all the 64-bit (x64) ODAC clients installed already but not the 32 bit ones (x32). Installed the 32-bit ODAC and the problem disappeared.

How to check the version of installed ODAC: Look in folder C:\Windows\assembly. The "Processor Architecture" property will inform the platform of installed ODAC.

Eight hours is a long time for the bulb to light up. No wonder I always have to slog at work :).

久夏青 2024-07-23 06:03:37

我在安装Oracle Data Tools for Visual Studio 2015后遇到了这个问题,然后与Oracle战斗了好一个小时。 我决定再次尝试重新安装 Oracle 客户端,而不是像文件复制、配置更改等那样混乱,这对我有用。

I encountered this problem after I installed Oracle Data Tools for Visual Studio 2015, and then fighting with Oracle for a good hour. I decided to try reinstalling Oracle client again instead of this mess with file copying, config changes, etc., and that worked for me.

梦途 2024-07-23 06:03:37

我遇到了类似的问题,根本原因是 GAC 有 2 个 oracle.dataaccess 版本,即 v4.0_4.112.2.0 和 v4.0_4.112.4.0 。 我的应用程序引用了 v4.0_4.112.2.0 ,因此当我从 GAC 中删除 v4.0_4.112.4.0 时,它工作正常。

GAC 路径:C:\Windows\Microsoft.NET\ assembly\GAC_64\Oracle.DataAccess

之前:
输入图片此处描述

之后:
输入图片此处描述

要删除版本,只需从 GAC 中删除相应的文件夹即可。

I faced a similar issue and the root cause was that GAC had 2 oracle.dataaccess versions i.e. v4.0_4.112.2.0 and v4.0_4.112.4.0 . My application was referring to v4.0_4.112.2.0 , so when I removed v4.0_4.112.4.0 from GAC, it worked fine.

GAC path : C:\Windows\Microsoft.NET\assembly\GAC_64\Oracle.DataAccess

Before :
enter image description here

After :
enter image description here

To remove a version, one can simply delete the corresponding folder from GAC.

み零 2024-07-23 06:03:37

因此,对于仍在与这个恶魔作斗争的任何人,请记住两件事:

  1. 您需要什么版本的 Oracle 数据库客户端
  2. 无论您需要 32 位版本还是 64 位版本。
    这两个取决于您的应用程序和 Oracle.DataAccess .dll 版本。

我不断收到此错误,因为我没有安装正确的 Oracle 数据库客户端版本。 当我需要 11g 时,我只安装了 19c。 您可以毫无问题地安装多个版本。

安装 32 位 11g Oracle 数据库客户端后,我终于成功了。 您可能会在 Oracle 软件交付云中找到旧版本的 Oracle 数据库客户端,只要仔细查找,它们就在那里。

So, for anyone still battling this demon, keep 2 things in mind:

  1. What version of Oracle Database Client you need.
  2. Whether you need the 32bit or 64bit version.
    These 2 depend on your application and Oracle.DataAccess .dll version.

I kept getting this error because I didn't have the correct Oracle Database Client version installed. I only had the 19c installed when I needed the 11g. You can have multiple versions installed with no problem whatsoever.

After installing the 32bit 11g Oracle Database Client, that finally did the trick for me. You may find older versions of the Oracle Database Client in Oracle's Software Delivery Cloud, just look for them carefully, they're there.

冷心人i 2024-07-23 06:03:37
  • 在 64 位计算机上,将“msvcr71.dll”从 C:\Windows\SysWOW64 复制到
    您的应用程序的 bin 目录。
  • 在 32 位计算机上,将“msvcr71.dll”从 C:\Windows\System32 复制到
    您的应用程序的 bin 目录。

http://randomdevtips.blogspot.com/2012 /06/provider-is-not-compat-with-version.html

  • On a 64-bit machine, copy "msvcr71.dll" from C:\Windows\SysWOW64 to
    the bin directory for your application.
  • On a 32-bit machine, copy "msvcr71.dll" from C:\Windows\System32 to
    the bin directory for your application.

http://randomdevtips.blogspot.com/2012/06/provider-is-not-compatible-with-version.html

克里斯的解决方案也对我有用。 然而,我确实收到了一条错误消息,其中指出:

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.

显然,在 Oraclish 的外语中,这意味着您的程序要么针对所有平台,要么针对 32 位机器。
只需将“项目属性”中的目标平台更改为 64 位即可,祝一切顺利。

Chris' solution worked for me as well. I did however get a follow error message that states:

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Apparently, in the foreign language of Oraclish, that means that your program are either targeting all platforms, or 32-bit machines.
Simply change your target platform in Project Properties to 64-bit and hope for the best.

淑女气质 2024-07-23 06:03:37

我对 Oracle.DataAccess.dll v4.121.2.0 也有同样的问题。 2 个家庭安装(32 和 64 位版本)。 32位版本有workerd,64位版本没有。

就我而言(经过 2 天的尝试),我发现问题在于 64 位家庭版本的权限。 该版本中的许多目录具有独占覆盖权限,其中“经过身份验证的用户”角色没有“读取”访问权限,这是默认在父目录上设置的。 这些子目录包括“bin”、“network/admin”、“nls”、“oracore”、“RDBMS”以及可能的其他子目录。 我通过从 sysinternals 中过滤掉“进程监视器”(Procmon.exe) 实用程序中的“访问被拒绝”结果来找到它们。 一旦权限从父目录继承到这些子子目录,一切就开始工作了。

我没有覆盖整个 oracle 主目录的权限,所以我一次只执行一个目录,但我想如果您不太担心安全性,您可以在整个相应的 oracle 主目录上重置它。

I had the same issue with Oracle.DataAccess.dll v4.121.2.0. with 2- homes installation (32 and 64 bit versions). 32-bit version workerd, 64-bit version didn't.

In my case (after 2 days of trying) I found that the problem was permissions on the 64-bit-home version. Many Directories in that version had exclusively overridden permissions where "Authenticated Users" role did not have "Read" access, which is set by default on the parent directory. Those sub-directories included "bin", "network/admin", "nls", "oracore", "RDBMS" and possibly others. I found them by filtering out "ACCESS DENIED" result in "Process Monitor" (Procmon.exe) utility from sysinternals. Once the permissions were inherited from the parent directory to those child subdirectories everything started to work.

I didn't what to override the permissions on the whole oracle home so I did them one directory at a time, but I guess if you don't worry about security so much you can reset it on the whole corresponding oracle home directory.

静谧 2024-07-23 06:03:37

这里有很多理论答案,但这里有一个工作示例,其中包含可以立即复制、粘贴和测试的代码:

  1. 我安装了 Oracle Express 数据库 OracleXE112,它已经附带了一些预安装的演示表。
  2. 当您启动安装程序时,系统会要求您输入密码。 我输入“xxx”作为密码。 (不在生产​​中使用)
  3. 我的服务器在计算机 192.168.1.158 上运行 在
  4. 服务器上,您必须明确允许 Windows 防火墙 中的进程 TNSLSNR.exe 的访问。 此进程侦听端口 1521。如果您从以下代码中收到超时错误,请检查您的防火墙。
  5. 选项 A:对于 C#(.NET2 或 .NET4),您可以下载 ODAC11,您必须从中将 Oracle.DataAccess.dll 添加到您的项目中。 此外,该 DLL 还依赖于:OraOps11w.dll、oci.dll、oraociei11.dll(130MB!)、msvcr80.dll。
    这些 DLL 必须与 EXE 位于同一目录中,或者您必须在以下位置指定 DLL 路径:HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.112.4.0\DllPath。 在 64 位计算机上,另外写入 HKLM\SOFTWARE\Wow6432Node\Oracle\...
  6. 选项 B: 如果您已下载 ODAC12,则需要 Oracle .DataAccess.dll、OraOps12w.dll、oci.dll、oraociei12.dll(160MB!)、oraons.dll、msvcr100.dll。 注册表路径为 HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.121.2.0\DllPath
  7. OPTION C: 如果您不想要超过 100 MB 的巨大 DLL,您可以选择应该下载 ODP.NET_Managed12.xxxxxxxx.zip,其中您可以找到 Oracle.ManagedDataAccess.dll,它只有 4 MB,是一个纯托管 DLL,也可以在 32 位和 64 位进程中工作,并且依赖于没有其他 DLL,也不需要任何注册表项。
  8. 以下 C# 代码适用于我无需在服务器端进行任何配置(只是默认安装):
using Oracle.DataAccess.Client;
or
using Oracle.ManagedDataAccess.Client;

....

string oradb = "Data Source=(DESCRIPTION="
    + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.158)(PORT=1521)))"
    + "(CONNECT_DATA=(SERVER=DEDICATED)));"
    + "User Id=SYSTEM;Password=xxx;";

using (OracleConnection conn = new OracleConnection(oradb)) 
{
    conn.Open();
    using (OracleCommand cmd = new OracleCommand())
    {
        cmd.Connection  = conn;
        cmd.CommandText = "select TABLESPACE_NAME from DBA_DATA_FILES";

        using (OracleDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {
                listBox.Items.Add(dr["TABLESPACE_NAME"]);
            }
        }
    }
}

Lots of theoretical answers here, but here comes a working example with code that you can copy and paste and test immediately:

  1. I installed the Oracle Express database OracleXE112 which already comes with some preinstalled demo tables.
  2. When you start the installer you are asked for a password. I entered "xxx" as password. (not used in production)
  3. My server runs on the machine 192.168.1.158
  4. On the server you must explicitely allow access for the process TNSLSNR.exe in the Windows Firewall. This process listens on port 1521. If you get a timeout error from the below code check your firewall.
  5. OPTION A: For C# (.NET2 or .NET4) you can download ODAC11, from which you have to add Oracle.DataAccess.dll to your project. Additionally this DLL depends on: OraOps11w.dll, oci.dll, oraociei11.dll (130MB!), msvcr80.dll.
    These DLLs must be in the same directory as the EXE or you must specify the DLL path in: HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.112.4.0\DllPath. On 64 bit machines write additionally to HKLM\SOFTWARE\Wow6432Node\Oracle\...
  6. OPTION B: If you have downloaded ODAC12 you need Oracle.DataAccess.dll, OraOps12w.dll, oci.dll, oraociei12.dll (160MB!), oraons.dll, msvcr100.dll. The Registry path is HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.121.2.0\DllPath
  7. OPTION C: If you don't want huge DLL's of more than 100 MB you should download ODP.NET_Managed12.x.x.x.xxxxx.zip in which you find Oracle.ManagedDataAccess.dll which is only 4 MB and is a pure managed DLL which works in 32 bit and 64 bit processes as well and depends on no other DLL and does not require any registry entries.
  8. The following C# code works for me without any configuration on the server side (just the default installation):
using Oracle.DataAccess.Client;
or
using Oracle.ManagedDataAccess.Client;

....

string oradb = "Data Source=(DESCRIPTION="
    + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.158)(PORT=1521)))"
    + "(CONNECT_DATA=(SERVER=DEDICATED)));"
    + "User Id=SYSTEM;Password=xxx;";

using (OracleConnection conn = new OracleConnection(oradb)) 
{
    conn.Open();
    using (OracleCommand cmd = new OracleCommand())
    {
        cmd.Connection  = conn;
        cmd.CommandText = "select TABLESPACE_NAME from DBA_DATA_FILES";

        using (OracleDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {
                listBox.Items.Add(dr["TABLESPACE_NAME"]);
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文