Link to home
Start Free TrialLog in
Avatar of Mahesh Badge
Mahesh Badge

asked on

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

I am trying to connect to Oracle Database from Visual Studio 2008 installed on Windows 7 64 bit machine. I am connecting using C# code. On firing Connection.Open(), I am getting the error as following:
"BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed"
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Compile your app as 32 bit - the x86 option.
User generated image
Avatar of Mahesh Badge
Mahesh Badge

ASKER

Yes, I tried the same too but it did not resolve my error. Still same error.
You recompiled and used the newly compiled exe ?  Please confirm.  The error message seems to say you are still using a 64 bit version of the exe.  (Or it is an irrelevant error message not related to your real problem).
I am trying to connect Oracle from a Web Application. And the Oracle Client installed is Version 10.2 (32 bit).
In that case, does your application pool allow 32 bit processes? Check in your IIS (a screen shot is attached).User generated image
Why not install the 64 bit Oracle client?
No matter the Bit version of the client installed, I would go with the new Managed Client.  It doesn't require an Oracle Client install like the other drivers do.

I've been using it since it came out and am quite happy with it.

They are available under here.  Just pick the correct Bit version for the target application:
http://www.oracle.com/technetwork/topics/dotnet/downloads/net-downloads-160392.html

32-bit ODAC Xcopy and NuGet Downloads
64-bit ODAC Downloads - Oracle Universal Installer and Xcopy
Jeevan Bordoloi, I made the same changes in IIS.

johnsone, I tried installing  the 64 bit Client too but it did not work.
Are you getting the error locally or on the web server?
I am getting this error locally ...
Could you make a small winforms app that on a button press gets just one value back from your oracle database and displays it ?  Try it both with the x86 and any CPU options.

Why do this?
Because if neither work (with the same error message) - you have a problem on the Oracle side.
If the x86 option works and the other doesn't - it really is something to do with a 64 bit issue.
If both x86 and anyCPU work - Oracle is working, your app works both with 32 and 64 bit code, so something else is causing this error.
I have created a sample Web application in VS 2008. This has the button control on click event of which code for Oracle Connection is written. It is built with x86 option. Gives me the same error.
How many projects are in your solution?
Try removing and then re-installing the oracle components.
Re-installing has been tried many times but no luck ...
Can you try the Oracle Managed Client I suggested above?  There are less moving parts to troubleshoot when using it.
ASKER CERTIFIED SOLUTION
Avatar of Mahesh Badge
Mahesh Badge

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad it works for you but for future people that come across this question, I have one warning:
There are a LOT of unnecessary steps in that PDF.

You created an ODBC DSN for no reason.  When you add the reference to Oracle.DataAccess.dll you are not using ODBC.  You are using ODP.Net.

You also probably don't need all the providers you installed with .sql scripts you ran.

If you use the Managed Client like I suggested, you don't need the Oracle Client install at all.

There are probably more but those were the ones that jumped out at me.
Please refer the attachment it will give complete steps.
I read the attached file.  It has some unnecessary steps.

I posted what I did as a suggestion to others that not everything in there should be done.