Heim  >  Artikel  >  Datenbank  >  C#,delphi7在64位操作系统上连接Oracle 11g的问题和解决方案 Ba

C#,delphi7在64位操作系统上连接Oracle 11g的问题和解决方案 Ba

WBOY
WBOYOriginal
2016-06-07 15:37:132572Durchsuche

环境:windows2008R2企业版64位,安装Oracle 11g 64位版服务端。C#3.5开发的b/s系统,32位版。delphi7开发的c/s服务 错误提示: Oracle 11g 64位版在64位操作系统上连接Oracle的问题和解决方案 BadImageFormatException 同时解决Delphi7.0采用Oledb链接64位o

环境:windows2008R2企业版64位,安装Oracle 11g 64位版服务端。C#3.5开发的b/s系统,32位版。delphi7开发的c/s服务

错误提示:

Oracle 11g 64位版在64位操作系统上连接Oracle的问题和解决方案 BadImageFormatException

同时解决Delphi7.0采用Oledb链接64位oracle11g出现密码不正确的问题。

 

尝试加载Oracle客户端库时引发BadImageFomatException。如果在安装32位Oracle客户端组件的情况下以64位模式运行,将出现此问题。

错误原因是原来WinXP机子上所安装的OracleInstantClient是32位,所以编译的程序所用的OracleClient也是32位的,从而导致兼容问题。当然,如果在64位操作系统上重新安装64位的Oracle客户端再重新编译程序也是能解决问题的。这里我们介绍一种简单的方法来移植程序。

如果在服务器端安装32位的oracle9i客户端,要注意密码的大小写的问题,9i客户端默认会把密码转换成大写,要特别注意。

 

总之解决问题的方法是:在服务端再安装一个Oracle 11g 32位版的客户端

 

参考文章:http://blog.darkthread.net/blogs/darkthreadtw/archive/2008/10/19/system-data-oracleclient-requires-oracle-client-software-version-8-1-7.aspx

我的奮鬥-System.Data.OracleClient on Windows 2008 x64

自從家中與公司的機器分別改用Vista x64及Windows 2008 x64後,在享受爽快揮霍記憶體之餘,也一併開始體驗在新大陸拓荒的感覺。大部分的高階應用程式,多半可以x86虛擬環境執行,問題不大。但有不少涉及低階處理的程式選擇頓時劇減,例如: RamDisk因為Driver未具備簽章無法使用、能支援x64的免費防毒軟體屈指可數、之前提到重新Survey了DVD燒錄程式...

這些軟體上的短缺咬一咬牙就撐過了,最讓我痛苦的是原本部門大家慣用的ODP.NET 9207完全不支援x64版本,安裝程式根本沒法跑!

Google之後,知道Oracle 10.2g開始Support Vista/Windows 2008 x64,但無奈ORACLE網站不知怎麼,連續好幾天,下載連結都出現HTTP 404。最後終於在兩週後讓我下載到近500M的10204_vista_w2k8_x64_production_client.zip,安裝完成馬上用現有的專案試了一下,結果出現:

System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.

檢視權限等OK,試了一下重新開機,訊息變了:

System.InvalidOperationException: Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B).

似乎是DLL版本不對,但我明明裝的是64bit Oracle Client,.NET程式限定Build for x86 CPU,為什麼跟我說: 在64 Mode下去讀了32bit Oracle Client? 感覺上恰恰相反才對。

反覆測試,忽然發現如果設定Build for AnyCPU或x64就可以順利連上Oracle,唯獨設成x86時會出現上述疑似相反的錯誤。設成x86時去讀取64bit Oracle Client DLL會發生問題,十分合理,只是一開始的錯誤訊息讓我有些迷惑。如果這是問題,那麼是否同時再裝32bit Oracle Client就好? 但,System.Data.OracleClient要如何知道該用32bit或64bit Oracle Client? 我每次都要改Registry或設PATH環境變數來切換使用的Client嗎? 一切的疑問,都要試了才知道!!

找到10203_vista_w2k8_x86_production_client.zip,裝在另一個目錄下(c:\oracle\ora10g vs c:\oracle\ora10g_x86),重新登入讓PATH環境變數中的c:\oracle\oar10g_x86\bin生效,x86就可以跑了。抱著期待的心情切成x64再跑,Yes! 也成功了!! 但這是x64 .NET用32bit Oracle Client的結果嗎?

使用Process Monitor解開了疑惑: System.Data.OracleClient會沿著PATH環境變數的路徑去找oci.dll,在x64下會略過c:\oracle\ora10g_x86\bin\oci.dll,找到c:\oracle\ora10g\bin\oci.dll後連線;x86時則是找到c:\oracle\ora10g_x86\bin\oci.dll就結束尋找,AnyCPU則與x64的行為相同。
(記得之前的PB6連Oracle9嗎? 一樣是用PATH法)

換句話說,OracleClient會依x64/x86決定適當的Oracle Client版本,不必勞煩我去手工切換。因此,如果想在Windows 2008/Vista x64上使用System.Data.Oraclient,最好32bit/64bit兩種10.2+版本的Oracle Client都要裝,並確定PATH變數中二者的bin目錄都有在其中,一切就搞定了。

說來簡單,卻花了我好幾個星期才解決,希望這點心得對其他也在x64叢林中挺進的同胞們有些幫助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn