错误图像格式异常.在安装了 32 位 Oracle 客户端组件的情况下以 64 位模式运行时会发生这种情况 [英] BadImageFormatException. This will occur when running in 64 bit mode with the 32 bit Oracle client components installed

查看:19
本文介绍了错误图像格式异常.在安装了 32 位 Oracle 客户端组件的情况下以 64 位模式运行时会发生这种情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .Net 应用程序尝试连接到 oracle 数据库时遇到此错误.

I am getting this error while on of my .Net application are trying to make a connection to oracle database.

错误表示在安装了 32 位 Oracle 客户端组件的 64 位模式下运行时会出现此问题..但我已经多次确定客户端安装在x64 位不是 32.

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)

推荐答案

一种解决方案是在您的机器上同时安装 x86(32 位)和 x64 Oracle 客户端,那么您的应用程序在哪种架构上运行都没有关系.

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.

这是在一台机器上安装 x86 和 x64 Oracle 客户端的说明:

Here an instruction to install x86 and x64 Oracle client on one machine:

假设:Oracle Home 名为 OraClient11g_home1,客户端版本为 11gR2

Assumptions: Oracle Home is called OraClient11g_home1, Client Version is 11gR2

下载并安装 Oracle x86 Client,例如到 C:Oracle11.2Client_x86

Download and install Oracle x86 Client, for example into C:Oracle11.2Client_x86

下载并安装 Oracle x64 Client 到不同的文件夹,例如到 C:Oracle11.2Client_x64

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

打开命令行工具,进入文件夹%WINDIR%System32(通常是C:WindowsSystem32)并创建一个符号链接ora112 到文件夹 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)

切换到文件夹%WINDIR%SysWOW64(通常是C:WindowsSysWOW64)并创建一个符号链接ora112到文件夹 C:Oracle11.2Client_x86,(见下文)

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

修改PATH环境变量,替换C:Oracle11.2Client_x86C:Oracle11.2Client_x64等所有条目C:WindowsSystem32ora112,各自的 in 子文件夹.注意:C:WindowsSysWOW64ora112不能在PATH环境中.

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.

如果需要,将您的 ORACLE_HOME 环境变量设置为 C:WindowsSystem32ora112

If needed set your ORACLE_HOME environment variable to C:WindowsSystem32ora112

打开您的注册表编辑器.将注册表值 HKLMSoftwareORACLEKEY_OraClient11g_home1ORACLE_HOME 设置为 C:WindowsSystem32ora112

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

将注册表值 HKLMSoftwareWow6432NodeORACLEKEY_OraClient11g_home1ORACLE_HOME 设置为 C:WindowsSystem32ora112(不是 C:WindowsSysWOW64ora112)

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

你完成了!现在您可以无缝地使用 x86 和 x64 Oracle 客户端,即 x86 应用程序将加载 x86 库,x64 应用程序加载 x64 库而无需对您的系统进行任何进一步修改.

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.

可能将 TNS_ADMIN 环境变量(注册表中的 TNS_ADMIN 条目)设置为一个公共位置是一个明智的选择,例如 TNS_ADMIN=C:OracleCommon etwork.

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.

创建符号链接的命令:

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

注意事项:

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

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

尽管名称不同,文件夹 C:WindowsSystem32 包含 x64 库,而 C:WindowsSysWOW64 包含 x86(32 位)库.不要混淆.

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

这篇关于错误图像格式异常.在安装了 32 位 Oracle 客户端组件的情况下以 64 位模式运行时会发生这种情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆