本机:XP(32位)+Oracle10g(32位)
服务器:Windows Server 2008(64位)+Oracle11g(64位)+IIS
开发调试过程中(项目属性any CPU),从本机访问服务器上的数据库正常。但是把程序部署到服务器后,程序无法访问服务器上的数据库,并报错“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.
”
解决办法:在服务器上安装 Oracle Client(32位)的(本次安装的是10gClient 32位),重启电脑后,服务器上的程序正常访问数据库。
原因综合网上资料,个人理解为:因为服务器上的程序是以32位运行(w3wp.exe *32).访问Oracle数据库需要32位的oci.dll。但是服务器的oci.dll为64位,所以总是有上面的错误提示。当时手上只有32位的 oracle10g client ,报着试一试的心态装好后,重启电脑,访问成功。
装32位client的最终目的是把32位的oci.dll放到服务器上,并自动在系统环境变量里写上路径。刚验证了一下,把环境变量路径改了,重启,就又连不上了。
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: 试图加载格式不正确的程序。 (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 MFIAES.Classes.Users.userLogin(String custID, String password) in F:\E\CShapProject\MFIAES\MFIAES\Classes\Users.cs:line 143 at MFIAES._Default.btnLogin_Click(Object sender, EventArgs e) in F:\E\CShapProject\MFIAES\MFIAES\Default.aspx.cs:line 27
这是报出来的错误信息。