How to tell System.Data.OracleClient to use the 64 bit Oracle Driver

chiccodoro picture chiccodoro · Jul 22, 2011 · Viewed 24.3k times · Source

I am trying to run a .NET application which uses System.Data.OracleClient on a Win7 x64 workstation. The workstation has a 32bit Oracle client installed, which leads to the following error message:

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.

So this is my long journey of tries and failures:

  1. I tried to install the Oracle client win64_11gR2_client. But during the setup process it crashes without any comment.
  2. I followed an answer from a different SO thread, tried and extracted the instantclient-basic-windows.x64-11.2.0.2.0, and put the folder containing the binaries in the windows PATH variable. I still get the same error message though (even after rebooting).
  3. I followed the "alternative way" from this answer and copied the files oci.dll, orannzsbb11.dll, and oraociei11.dll into the bin/ folder of my web site project. Still the same error message.
  4. I tried and copied all files from the instant client into that directory and tried again, without success.
  5. I installed ODAC112021Xcopy_x64.zip and put the installation folder and the bin folder in the windows PATH variable. No success.
  6. I put my hope on this answer and reviewed the DllPath in the registry (which is actually supposed to relate to ODP.NET as opposed to System.Data.OracleClient) and saw that DllPath points to the correct x64 installation of ODAC, so, if my application wasn't using System.Data.OracleClient, it should work,b but since it does use that, it still failed.
  7. I googled and stackoverflew but didn't find anything else that the posts I already referred to.
  8. I carefully crafted this SO question in the hope of getting any insightful advice from an enlightened SO user.
  9. After getting the first answer from b_levitt, I tried and added the following lines to the Global.asax at Application_Start:

    Environment.SetEnvironmentVariable("ORACLE_HOME", @"C:\OracleProducts\Odac-11.2.0.2.1-x64");
    Environment.SetEnvironmentVariable("PATH", @"C:\OracleProducts\Odac-11.2.0.2.1-x64;C:\OracleProducts\Odac-11.2.0.2.1-x64\bin");
    

    C:\OracleProducts\Odac-11.2.0.2.1-x64 is where I installed the ODAC 64 bit xcopy version. No success either.

On a related note, I even tried to force my .NET app into 32bit mode without success, but that's a different thing. I need a forward-looking solution, which means 64bit.

Answer

b_levitt picture b_levitt · Jul 26, 2011

Your #5 should have worked but you also need to set the ORACLE_HOME environment variable. I've done this many times including recently with the very xcopy install that you are using. Please check out my experience with the xcopy install and let me know what kind of additional errors that you get.

In my case I was setting it up for asp.net, but winforms is even easier. You can open a cmd window, use the "set" command to set both the PATH and the ORACLE_HOME environment variables and then run your app from that same cmd window. Once you get the bugs worked out, you can use the Environment.SetEnvironmentVariable to set these within your code.

For the record, I do avoid installing the oracle client on client machines by handling all of the business logic via web services. That way I only need the oracle components on the web server.