本文介绍了BadImageFormatException。这将在64位模式下安装了32位Oracle客户端组件运行时,会出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误,而在我的应用程序试图让到Oracle数据库的连接。

该错误说 64位模式下安装了32位Oracle客户端组件运行时,会出现此问题。。 But我已经确定很多次,客户端安装在 64 位不是 32

 日期时间:2014年6月8日上午10点57分55秒信息:System.InvalidOperationException:尝试加载Oracle客户端库扔BadImageFormatException。在64位模式安装了32位Oracle客户端组件运行时,会出现此问题。 ---> System.BadImageFormatException:试图用不正确的格式加载程序。 (从HRESULT异常:0x8007000B)
       在System.Data.Common.UnsafeNativeMethods.OCILobCopy2(IntPtr的svchp,IntPtr的errhp,IntPtr的dst_locp,IntPtr的src_locp,UINT64量,UINT64 DST_OFFSET,UINT64 src_offset)
       在System.Data.OracleClient.OCI.DetermineClientVersion()
       ---内部异常堆栈跟踪的结尾---
       在System.Data.OracleClient.OCI.DetermineClientVersion()
       在System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(用户名字符串,字符串密码,字符串的serverName,布尔integratedSecurity,布尔UNI code,布尔omitOracleConnectionName)
       在System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
       在System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions选项,对象poolGroupProviderInfo,池类DBConnectionPool,的DbConnection owningObject)
       在System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(的DbConnection owningConnection,池类DBConnectionPool,DbConnectionOptions选项)
       在System.Data.ProviderBase.DbConnectionPool.CreateObject(的DbConnection owningObject)
       在System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(的DbConnection owningObject)
       在System.Data.ProviderBase.DbConnectionPool.GetConnection(的DbConnection owningObject)
       在System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection owningConnection)
       在System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory的)
       在System.Data.OracleClient.OracleConnection.Open()
       在CustomizedSetupInstaller.Runscripts.InitializeDBObjects(字符串的connectionString,字符串dbProvider)
 

解决方案

一个解决办法是安装在x86(32位)和x64的Oracle客户端的机器上,那么就无所谓哪个架构您的应用程序正在运行。

下面的指令在一台计算机上安装x86和x64的Oracle客户端:

假设: Oracle主叫 OraClient11g_home1 ,客户端版本为11gR2的

  • 有选择地删除所有已安装的Oracle客户端

  • 下载并安装Oracle x86客户,例如为 C:\ ORACLE \ 11.2 \ Client_x86

  • 下载并安装Oracle x64客户端到不同的文件夹,例如 C:\ ORACLE \ 11.2 \ Client_x64

  • 打开命令行工具,去到文件夹%WINDIR%\ System32下,一般 C:\ Windows \ System32下并创建符号链接 ora112 到文件夹 C:\ ORACLE \ 11.2 \ Client_x64 (见下文)

  • 切换到文件夹%WINDIR%\ Syswow64资料,一般 C:\ WINDOWS \ SysWOW64中并创建符号链接 ora112 到文件夹 C:\ ORACLE \ 11.2 \ Client_x86 ,(见下文)

  • 修改 PATH 环境变量,替换像所有条目C:\ ORACLE \ 11.2 \ Client_x86 C:\ ORACLE \ 11.2 \ Client_x64 C:\ WINDOWS \ SYSTEM32 \ ora112 ,各自的<$ C C> $ \ BIN 子文件夹。注: C:\ WINDOWS \ Syswow64资料\ ora112 不需要在PATH环境

  • 如果需要设置侑 ORACLE_HOME 环境变量 C:\ WINDOWS \ SYSTEM32 \ ora112

  • 打开注册表编辑器。设置注册表值 HKLM \ SOFTWARE \ ORACLE \ KEY_OraClient11g_home1 \ ORACLE_HOME C:\ WINDOWS \ SYSTEM32 \ ora112

  • 设置注册表值 HKLM \ SOFTWARE \ Wow6432Node \ ORACLE \ KEY_OraClient11g_home1 \ ORACLE_HOME C:\ WINDOWS \ SYSTEM32 \ ora112 (而不是 C:\ WINDOWS \ Syswow64资料\ ora112

  • 您完成了!现在你可以使用x86和x64的Oracle客户端无缝在一起,即一个x86应用程序将加载在x86库,一个64位应用程序加载64位库,没有你的系统上的任何进一步的修改。

  • 也许这是一个明智的选择来设置你的 TNS_ADMIN 环境变量(RESP。 TNS_ADMIN 中的条目注册)到一个共同的位置,例如 TNS_ADMIN = C:\ ORACLE \公用\网络

命令来创建符号链接:

CD C:\ Windows \ System32下MKLINK / D ora112 C:\ ORACLE \ 11.2 \ Client_x64CD C:\ WINDOWS \ Syswow64资料MKLINK / D ora112 C:\ ORACLE \ 11.2 \ Client_x86

注:

这两个符号链接必须具有相同的名称,例如: ora112

尽管他们的名字的文件夹 C:\ Windows \ System32下包含了64位的库,而 C:\ WINDOWS \ SysWOW64中包含在x86(32位)库。不要混淆。

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)
解决方案

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

  • 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 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 is not needed in PATH environment.

  • If needed set yor 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\System32mklink /d ora112 C:\Oracle\11.2\Client_x64cd C:\Windows\SysWOW64mklink /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 be confused.

这篇关于BadImageFormatException。这将在64位模式下安装了32位Oracle客户端组件运行时,会出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 11:48