Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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) 
like image 694
Maven Avatar asked Jun 08 '14 08:06

Maven


People also ask

Can 32 bit and 64 bit Oracle clients coexist?

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 the difference between 32 bit and 64 bit Oracle client?

A: No. The 64-bit version simply allows your program to use more memory. There is no real advantage to 64-bit unless you want to fetch a one-billion-row table all into memory on your PC within a Toad data grid.

How do I know if I have 32 bit or 64 bit Oracle client?

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.

How can I tell what version of Oracle client is installed?

Hi, In the sql plus prompt type. SQL> select * from v$version; You will get your oracle client verison.


1 Answers

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 11gR2

  • Optionally 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 link ora112 to folder C:\Oracle\11.2\Client_x64 (see commands section below)

  • Change to folder %WINDIR%\SysWOW64 (typically C:\Windows\SysWOW64) and create a symbolic link ora112 to folder C:\Oracle\11.2\Client_x86, (see below)

  • Modify the PATH environment variable, replace all entries like C:\Oracle\11.2\Client_x86 and C:\Oracle\11.2\Client_x64 by C:\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 to C:\Windows\System32\ora112

  • Open your Registry Editor. Set Registry value HKLM\Software\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112

  • Set Registry value HKLM\Software\Wow6432Node\ORACLE\KEY_OraClient11g_home1\ORACLE_HOME to C:\Windows\System32\ora112 (not C:\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 example TNS_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, whereas C:\Windows\SysWOW64 contains the x86 (32-bit) libraries. Don't get confused.

like image 97
Wernfried Domscheit Avatar answered Oct 20 '22 14:10

Wernfried Domscheit