The provider is not compatible with the version of Oracle client

前端 未结 27 1176
一生所求
一生所求 2020-11-22 05:37

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 pag

相关标签:
27条回答
  • 2020-11-22 06:25

    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.

    0 讨论(0)
  • 2020-11-22 06:26

    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.

    0 讨论(0)
  • 2020-11-22 06:26

    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!

    0 讨论(0)
  • 2020-11-22 06:26

    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> 
      
    0 讨论(0)
  • 2020-11-22 06:29

    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.

    • 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.

    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.

    0 讨论(0)
  • 2020-11-22 06:31

    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?

    0 讨论(0)
提交回复
热议问题