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

后端 未结 21 2047
南方客
南方客 2020-11-21 13:30

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

相关标签:
21条回答
  • 2020-11-21 13:56

    Make Enable32bit Application to TRUE in the IIS App pool which you are consuming

    0 讨论(0)
  • 2020-11-21 13:58

    In my situation, the Oracle 11.2 32-bit client was installed on my 64-bit Windows 2008 R2 OS.

    My solution: In the Advanced Settings for the Application Pool assigned to my ASP.NET application, I set Enable 32-Bit Applications to True.

    Please see below for the standalone .ashx test script that I used to test the ability to connect to Oracle. Before making the Application Pool change, its response was:

    [Running as 64-bit] Connection failed.
    

    ...and after the Application Pool change:

    [Running as 32-bit] Connection succeeded.
    

    TestOracle.ashx – Script to Test an Oracle Connection via System.Data.OracleClient:

    To use: Change the user, password and host variables as appropriate.

    Note that this script can be used in a standalone fashion without disturbing your ASP.NET web application project file. Just drop it in your application folder.

    <%@ WebHandler Language="C#" Class="Handler1" %>
    <%@ Assembly Name="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>
    
    using System;
    using System.Data.OracleClient;
    using System.Web;
    
    public class Handler1 : IHttpHandler
    {
        private static readonly string m_User = "USER";
        private static readonly string m_Password = "PASSWORD";
        private static readonly string m_Host = "HOST";
    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
    
            string result = TestOracleConnection();
            context.Response.Write(result);
        }
    
        public bool IsReusable
        {
            get { return false; }
        }
    
        private string TestOracleConnection()
        {
            string result = IntPtr.Size == 8 ?
                "[Running as 64-bit]" : "[Running as 32-bit]";
    
            try
            {
                string connString = String.Format(
                  "Data Source={0};Password={1};User ID={2};",
                  m_Host, m_User, m_Password);
    
                OracleConnection oradb = new OracleConnection();
                oradb.ConnectionString = connString;
                oradb.Open();
                oradb.Close();
                result += " Connection succeeded.";
            }
            catch
            {
                result += " Connection failed.";
            }
    
            return result;
        }
    }
    
    0 讨论(0)
  • 2020-11-21 13:58

    I would like to add a resolution that worked for me. Setup: Oracle 11g 64 bits running on Windows 2008 R2 (64 bits OS)

    Client is a .net framework 3.5 application (ported from 2.0) compiled with x86 platform setting.

    I had the exact same issue of BadImageFormatException. Compiling to 64 bits eliminates the exception but it was not an option for me as my app is using 32 bits activex components who do not work in 64 bits.

    I solved the issue by downloading Oracle Instant Client 11 (this is just a bunch of DLL than can be xcopied) from Oracle website, and copying the files in my application files directory. See here : http://www.oracle.com/technetwork/database/features/oci/instant-client-wp-131479.pdf

    This has solved the issue, from ProcMon tool I can see that the locally copied oci.dll gets loaded by System.Data.OracleClient and everything is fine.

    It could probably be done by changing environment settings like proposed above, but this method has the advantage of not altering any settings on the server configuration.

    0 讨论(0)
  • 2020-11-21 13:59

    I had the same problem in SSIS 2008. I tried to connect to an Oracle 11g using ODAC 12c 32 bit. Tried to install ODAC 12c 64 bit as well. SSIS was actually able to preview the table but when trying to run the package it was giving this error message. Nothing helped. Switched to VS 2013, now it was running in debug mode but got the same error when the running the package using dtexec /f filename. Then I found this page: http://sqlmag.com/comment/reply/17881.

    To make it short it says: (if the page is still there just go to the page and follow the instrucrtions...) 1) Download and install the latest version of odac 64 bit xcopy from oracle site. 2) Download and install the latest version of odac 32 bit xcopy from oracle site. How? open a cmd shell AS AN ADMINSTARTOR and run: c:\64bitODACLocation> install.bat oledb c:\odac\odac64. the first parameter is the component you want to install. The second param is where to install to. install the 32 version as well like this: c:\32bitODACLocation> install.bat oledb c:\odac\odac32. 3) Change the path of the system to include c:\odac\odac32; c:\odac\odac32\bin; c:\odac\odac64;c:\odac\odac64\bin IN THIS ORDER. 4) Restart the machine. 5) make sure you have the same tnsnames.ora in both odac32\admin\network and odac64\admin\network folders (or at least the same entry for your connection). 6) Now open up SSIS in visual studio (I used the free 2013 version with the ssis package) - Use OLEDB and then select the Oracle Provider for OLE DB provider as your connection type. Set the name of the entry in your tnsnames.ora as the "server or file name". Username is your schema name (db name) and password is the password for schema. you are done!

    Again, you can find the very detailed solution and much more in the original site.

    This was the only thing which worked for me and did not mess up my environment.

    Cheers! gcr

    0 讨论(0)
  • 2020-11-21 13:59

    Please download the correct version of Oracle Client like Oracle Client 11.2 32-Bit; which resolved the problem for me.

    0 讨论(0)
  • 2020-11-21 13:59

    Just build your code in x86 mode not in AnyCpu.

    0 讨论(0)
提交回复
热议问题