2015-10-13 77 views
0

我希望我的应用程序使用Oracle 11g ODAC,但它似乎是使用那些用于12c .... 如何强制我的应用程序使用11g ODAC?想使用ODAC的特定版本

出于某种原因,我有以下的客户和ODT在我的电脑(Windows 7的SP1专业版64位):

- Oracle 11g Client (64-bit) version 11.2.0.3.0 
- Oracle 12c Client (64-bit) version 12.1.0.1.0 
- Oracle 12c ODT (Oracle Developer Tools for Visual Studio) (32-bit) 

而且,我的NET项目(视觉工作室2013年)referes“Oracle.DataAccess .DLL”存储在: C:\ WINDOWS \ Microsoft.NET \装配\ GAC_64 \ Oracle.DataAccess \ v4.0_4.112.3.0__89b483f429c47342

我的环境路径的顺序是这样的:

C:\oracle12c\product\12.1.0\client_2; 
C:\oracle12c\product\12.1.0\client_2\bin; 
C:\oracle12c\product\12.1.0\client_1; 
C:\oracle12c\product\12.1.0\client_1\bin; 
C:\Oracle\product\11.2.0\client_1; 
C:\Oracle\product\11.2.0\client_1\bin; 

我试图在这样的web.config文件中指定的DLLPath:

<oracle.dataaccess.client> 
    <settings> 
     <add name="DllPath" value="C:\Oracle\product\11.2.0\client_1\bin"/> 
    </settings> 
</oracle.dataaccess.client> 

但是,这是行不通的。 当的OracleConnection类的构造函数被调用时,我得到以下错误:

System.TypeInitializationException: 
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 
    at Oracle.DataAccess.Client.OracleInit.Initialize() 
    at Oracle.DataAccess.Client.OracleConnection..cctor() 
    --- End of inner exception stack trace --- 

任何信息都将是有益的。先谢谢你!

--- UPDATE 10月14日通过Yukapod ---

我发现我的应用程序不需要12C ODT 32位版本,所以我从我的电脑中删除它,并再次尝试。 然而,情况并没有改变;在调用OracleConnection类的构造函数之后,我仍然收到“提供程序与Oracle客户端版本不兼容”错误。我不知道哪里出了问题....

我仍然在我的web.config配置如下:

<oracle.dataaccess.client> 
    <settings> 
     <add name="DllPath" value="C:\Oracle\product\11.2.0\client_1\bin"/> 
    </settings> 
</oracle.dataaccess.client> 

而且,这是我目前的环境PATH变量:

C:\oracle12c\product\12.1.0\client_1; 
C:\oracle12c\product\12.1.0\client_1\bin; 
C:\Oracle\product\11.2.0\client_1; 
C:\Oracle\product\11.2.0\client_1\bin; 

其中

C:\oracle12c\product\12.1.0\client_1 
    -> ORACLE_HOME for Oracle 12c Client (64-bit) version 12.1.0.1.0 
Oracle\product\11.2.0\client_1 
    -> ORACLE HOME for Oracle 11g Client (64-bit) version 11.2.0.3.0 

即使我颠倒了PATH变量的顺序(我的意思是,让11克是第一位的),结果没有改变(仍然有相同的错误)。如果有人知道,任何类型的信息都会非常有帮助。再次提前谢谢你!

+0

您的应用程序尝试使用11g ODAC:C:\ Windows \ Microsoft.NET \ assembly \ GAC_64 \ Oracle.DataAccess \ v4.0_4。 ** ** 112。3.0__89b483f429c47342。但是,它会加载64位版本的“Oracle.DataAccess.dll”,但它会找到(第一个)32位Oracle客户端二进制文件。如果你喜欢 - 或者在你的机器上同时使用32位和64位Oracle客户机,请按照以下说明安装它们:http://stackoverflow.com/questions/24104210/badimageformatexception-this-will-occur- 64-bit-mode-with-the-32#24120100 –

+0

感谢您的快速响应,Wernfried!我发现我的应用程序不再需要12c ODT 32位版本,所以我从我的PC中删除了它。然而,情况并没有改变...... – yukapod

+0

也看看这个:http://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-客户端#25412992。我的建议是完全删除所有Oracle安装(请参阅:http://stackoverflow.com/questions/28727721/how-can-i-completely-uninstall-oracle-11g/28728711#28728711)并进行新的全新安装。 –

回答

0

谢谢大家帮助我!我终于找到了这个问题的原因。

原因:

12C的政策DLL被重定向对11克所有参考到12C。

详情:

我第一次安装Oracle 11g客户端,然后安装12C的客户,所以在我的GAC(C两项政策文件夹:\ WINDOWS \ Microsoft.NET \装配\ GAC_64 \ Policy.4.112。甲骨文。DataAccess):

v4.0_4.112.3.0__89b483f429c47342 <== policy folder for 11g 
v4.0_4.121.1.0__89b483f429c47342 <== policy folder for 12c 

在每个文件夹中,您可以看到Policy。[version] .Oracle.DataAccess.config文件。

为11g中的配置文件是这样的:

<configuration> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/> 
      <bindingRedirect oldVersion="4.112.0.0-4.112.3.0" newVersion="4.112.3.0"/> <== This is OK! 
     </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
</configuration> 

这是一个为12C:

<configuration> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/> 
      <bindingRedirect oldVersion="4.112.0.0-4.112.9999.9999" newVersion="4.121.1.0"/> <== OMG!! The 11g version 4.0_4.112.3 is included! 
     </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
</configuration> 

我没有爱护环境PATH变量的顺序,或者我不必指定要使用DllPath的Oracle.DataAccess.dll的哪个版本。在我的情况下,以下是使用特定ODAC的关键点:

- Make sure that my application has a reference for Oracle.DataAccess.dll for 11g. 
- Remove/rename the policy folder for 12c (v4.0_4.121.1.0__89b483f429c47342) in GAC. 

然后,我终于可以使用11g了。