Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BadImageFormatException while using Oracle Client 64 bit and Visual Studio 2010!

Tags:

One of our dev team member got an error

Attempt to load oracle client libraries threw BadImageFormatException

It seems

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

But it was me who configured the system - Here's the specifications:

  • Windows 7 64-bit
  • Visual Studio 2010 Premium
  • Oracle Client 11g R2 64Bit installed as Runtime

Any thoughts?

like image 599
Data-Base Avatar asked May 03 '11 13:05

Data-Base


People also ask

What is the difference between 32 bit and 64 bit Oracle client?

1) 32bit Oracle is the Oracle that runs on all operating systems. It has a 4gig (or less, depending on OS) address limit. It uses 32bit pointers which are limited to 4gig. Now, 64bit can address a much larger memory space.

Can 32 bit Oracle client connect 64 bit database?

Yes you can do that, there's no limitation regarding that (64-bit, 32-bit).

Is Oracle client 64 bit?

Instant Client for Microsoft Windows (x64) 64-bit. Continuous innovation with Oracle partner ecosystem to deliver desired outcome for our customers.


2 Answers

I am sorry about adding a second answer but if you have 64 bit and 32 bit clients installed in the same machine you may encounter this problem too.

Two clients installed

C:\oracle\product\11.2.0\client32Bit C:\oracle\product\11.2.0\client64Bit 

Control your path Environment Variable. Which Oracle client is first, it is loaded before other one.

 echo %PATH%  XXXX;C:\oracle\product\11.2.0\client64Bit\BIN;XXX 

Since my 64bit Oracle Client is first in PATH, VS.NET tries to use it for Oracle Connections and throws Bad Image Exception.

  set PATH=C:\oracle\product\11.2.0\client32Bit\BIN;%PATH%   REM Visual Studio 2008   "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"   REM Visual Studio 2010   "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" 

After this you can connect oracle. Of course you can put 32Bit client first in path but I prefer to put 64 bit client before 32 bit for other applications.

like image 74
Atilla Ozgur Avatar answered Oct 23 '22 20:10

Atilla Ozgur


Same problem you may face also in Visual Studio 2013 and 64-bit Oracle Client (11 and 12 versions). My solution is:

a) Desktop project. Project properties > Build > disable 'Prefer 32-bit' checkbox.

b) ASP.NET project or web site. Main menu > TOOLS > Options > Project and Solutions > Web Projects > enable 'Use the 64 bit version of IIS Express for web sites and projects' checkbox.

like image 35
codemonkey Avatar answered Oct 23 '22 19:10

codemonkey