2010年9月21日 星期二

This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed

緣由

開發 Oracle 專案時,發生了下面的錯誤訊息

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. Inner exception message: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

環境

以下是我的開發環境

解決方法

    由於 ODAC 目前只有32 bits的程式,而VS2010方案(solution)指定Build Target 是 AnyCPU,在 IIS 7 上就會執行 64 bits。在 64 bits 的 Process 上載入 32 bits 的 Oracle client library 就會發生這樣的錯誤訊息。

   解決方式也很簡單,就是在 IIS 7 上指定 Application Pool 可以跑 32 bits 的程式。

  1. 找到執行該程式的 Application Pool. 我的例子是使用預設的 ASP.NET v4.0。
  2. 在右方的 Action Panel 上,點擊「Advanced Settings」
  3. 將 Enable 32-Bit Applications 設為 True

   image

結論

    此方法只適用在開發機器上,目的是為了使用 Oracle Developer Tools For Visual Studio。在正式機上,就應該安裝 64 bits 的 Oracle Client library.

沒有留言:

Share with Facebook