I am getting this error while on of my .Net
application are trying to make a connection to oracle database.
The error says that This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
. But I have made sure many times that the client installed in x64
bit not 32
.
Date Time: 6/8/2014 10:57:55 AM: System.InvalidOperationException: 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. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at System.Data.Common.UnsafeNativeMethods.OCILobCopy2(IntPtr svchp, IntPtr errhp, IntPtr dst_locp, IntPtr src_locp, UInt64 amount, UInt64 dst_offset, UInt64 src_offset)
at System.Data.OracleClient.OCI.DetermineClientVersion()
--- End of inner exception stack trace ---
at System.Data.OracleClient.OCI.DetermineClientVersion()
at System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName)
at System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
at System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OracleClient.OracleConnection.Open()
at CustomizedSetupInstaller.Runscripts.InitializeDBObjects(String connectionString, String dbProvider)
I developed desktop application using C#.net with 2.0 framework along with system.data.oracleclient for connecting oracle db and I was facing similar 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."
following solutions were applied
now, it work because application is set for 32bit and oracle 32bit client installed over Win2012 R2 server, hopefully will work for you.
To revise IIS
Comment:
Platform: Windows Server 2008 R2 Enterprise - 64Bit - IIS 7.5
In my situation, the Oracle 11.2 32-bit client was installed on my 64-bit Windows 2008 R2 OS.
My solution: In the Advanced Settings for the Application Pool assigned to my ASP.NET application, I set Enable 32-Bit Applications to True.
Please see below for the standalone .ashx test script that I used to test the ability to connect to Oracle. Before making the Application Pool change, its response was:
...and after the Application Pool change:
TestOracle.ashx – Script to Test an Oracle Connection via System.Data.OracleClient:
To use: Change the user, password and host variables as appropriate.
Note that this script can be used in a standalone fashion without disturbing your ASP.NET web application project file. Just drop it in your application folder.
Make sure that registry HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\ODP.NET\4.112.# DIIPath key is pointing to 32 bit Oarcle client BIN directory. For example, DIIPath value can be C:\app\User_name\11.2.0\client_32bit\bin
As it was pointed out in the comments, System.Data.OracleClient is deprecated. There is little reason to start using it so late in the game.
Also as pointed out in the comments (I've marked this as community wiki in observence), there is now a managed provider as part of the 12c and later versions of the odp.net package. This provider does NOT require any unmanaged dlls so this should be a non issue in that case.
If you would prefer to use the old unmanaged Oracle.DataAccess provider from oracle, the simplest solution is to set the "DllPath" configuration variable:
See "Search Order for Unmanaged DLLs" in http://docs.oracle.com/database/121/ODPNT/InstallODP.htm for more information
One solution is to install both x86 (32-bit) and x64 Oracle Clients on your machine, then it does not matter on which architecture your application is running.
Here an instruction to install x86 and x64 Oracle client on one machine:
Assumptions: Oracle Home is called
OraClient11g_home1
, Client Version is 11gR2Optionally remove any installed Oracle client (see How to uninstall / completely remove Oracle 11g (client)? if you face problems)
Download and install Oracle x86 Client, for example into
C:\Oracle\11.2\Client_x86
Download and install Oracle x64 Client into different folder, for example to
C:\Oracle\11.2\Client_x64
Open command line tool, go to folder %WINDIR%\System32, typically
C:\Windows\System32
and create a symbolic linkora112
to folderC:\Oracle\11.2\Client_x64
(see commands section below)Change to folder %WINDIR%\SysWOW64, typically
C:\Windows\SysWOW64
and create a symbolic linkora112
to folderC:\Oracle\11.2\Client_x86
, (see below)Modify the
PATH
environment variable, replace all entries likeC:\Oracle\11.2\Client_x86
andC:\Oracle\11.2\Client_x64
byC:\Windows\System32\ora112
, respective their\bin
subfolder. Note:C:\Windows\SysWOW64\ora112
must not be in PATH environment.If needed set your
ORACLE_HOME
environment variable toC:\Windows\System32\ora112
Open your Registry Editor. Set Registry value
HKLM\Software\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME
toC:\Windows\System32\ora112
Set Registry value
HKLM\Software\Wow6432Node\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME
toC:\Windows\System32\ora112
(notC:\Windows\SysWOW64\ora112
)You are done! Now you can use x86 and x64 Oracle client seamless together, i.e. an x86 application will load the x86 libraries, an x64 application loads the x64 libraries without any further modification on your system.
Probably it is a wise option to set your
TNS_ADMIN
environment variable (resp.TNS_ADMIN
entries in Registry) to a common location, for exampleTNS_ADMIN=C:\Oracle\Common\network
.Commands to create symbolic links:
cd C:\Windows\System32 mklink /d ora112 C:\Oracle\11.2\Client_x64 cd C:\Windows\SysWOW64 mklink /d ora112 C:\Oracle\11.2\Client_x86
Notes:
Both symbolic links must have the same name, e.g.
ora112
.Despite of their names folder
C:\Windows\System32
contains the x64 libraries, whereasC:\Windows\SysWOW64
contains the x86 (32-bit) libraries. Don't be confused.