Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 957
chiccodoro Avatar asked Jul 22 '11 14:07

chiccodoro


People also ask

How can I tell if Oracle client is 32-bit or 64-bit?

The fastest way to see if an Oracle Client is 64bit or 32bit, too look for "lib32" and "lib" folders under ORACLE_HOME. If the Oracle Client is 32 bit, it will contain a "lib" folder; but if it is a 64 bit Oracle Client it will have both "lib" and "lib32" folders. Also, starting in Oracle 11.2.

Can I install both 32-bit and 64-bit Oracle client?

You can install Oracle 32-bit and Oracle 64-bit on the same server. The two installs must reside in different ORACLE_HOME directories though. So install Oracle 32-bit in a different directory than your 64-bit version and they will both coexist quite nicely.

What is System data OracleClient?

Data. OracleClient is a Microsoft . NET data provider allowing you to connect to an Oracle database. The provider is deprecated and it should not be used - Oracle and ADO.NET.


2 Answers

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.

like image 190
b_levitt Avatar answered Sep 18 '22 06:09

b_levitt


I had the same problem you have. I found most of my answers through Oracle forums and here at stackoverflow. I can't post links for reference but I can give you some things to try out.

  1. Also include OraOps11w.dll in your bin directory along with the other Oracle dll files.
  2. Go to the project properties|Reference Paths, add C:\Windows\Microsoft.NET\Framework64\v2.0.50727 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319 to the Reference paths depending on which framework version the project is using.
  3. **Fuzzy part that I don't remember well: Remove the System.Data.OracleClient current reference and add the new reference from C:\Windows\Microsoft.NET\Framework64\v2.0.50727 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319 to the Reference paths depending on which framework version the project is using.

See if the exception goes away.

FYI, Microsoft is dropping Oracle data provider (in ADO.NET) support in the near future. It currently works through .NET 4, but it is a good idea to start testing the native Oracle drivers.

like image 42
mozi Avatar answered Sep 22 '22 06:09

mozi