Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

.net - 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)
question from:https://stackoverflow.com/questions/24104210/badimageformatexception-this-will-occur-when-running-in-64-bit-mode-with-the-32

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:Oracle11.2Client_x86

  • Download and install Oracle x64 Client into different folder, for example to C:Oracle11.2Client_x64

  • Open command line tool, go to folder %WINDIR%System32 (typically C:WindowsSystem32) and create a symbolic link ora112 to folder C:Oracle11.2Client_x64 (see commands section below)

  • Change to folder %WINDIR%SysWOW64 (typically C:WindowsSysWOW64) and create a symbolic link ora112 to folder C:Oracle11.2Client_x86, (see below)

  • Modify the PATH environment variable, replace all entries like C:Oracle11.2Client_x86 and C:Oracle11.2Client_x64 by C:WindowsSystem32ora112, respective their in subfolder. Note: C:WindowsSysWOW64ora112 must not be in PATH environment.

  • If needed set your ORACLE_HOME environment variable to C:WindowsSystem32ora112

  • Open your Registry Editor. Set Registry value HKLMSoftwareORACLEKEY_OraClient11g_home1ORACLE_HOME to C:WindowsSystem32ora112

  • Set Registry value HKLMSoftwareWow6432NodeORACLEKEY_OraClient11g_home1ORACLE_HOME to C:WindowsSystem32ora112 (not C:WindowsSysWOW64ora112)

  • 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:OracleCommon etwork.

Commands to create symbolic links:

cd C:WindowsSystem32
mklink /d ora112 C:Oracle11.2Client_x64
cd C:WindowsSysWOW64
mklink /d ora112 C:Oracle11.2Client_x86

Notes:

Both symbolic links must have the same name, e.g. ora112.

Despite of their names folder C:WindowsSystem32 contains the x64 libraries, whereas C:WindowsSysWOW64 contains the x86 (32-bit) libraries. Don't get confused.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...