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

后端 未结 21 2239
南方客
南方客 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: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;
        }
    }
    

提交回复
热议问题