Mark Tabor

Mark Tabor

  • 930
  • 1.7k
  • 344.9k

Oracle connection with sample asp.net WEB FORM APPLICATION

Mar 15 2022 6:22 PM

I have a simple asp.net web form application when i am opening the connection I am getting this error 

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.

below is my code.

  protected void Page_Load(object sender, EventArgs e)
    {
      string conStr = ConfigurationManager.ConnectionStrings["myconestring"].ToString();

      OracleConnection con = null;
      OracleCommand cmd = null;
      OracleDataReader rd = null;
      string val = null;

      try
      {
        using (con = new OracleConnection(conStr))
        {
          cmd = new OracleCommand();
          cmd.CommandText = "select count(*) from child";
          cmd.Connection = con;
          con.Open();
          rd = cmd.ExecuteReader();
          rd.Read();
          val = rd.GetInt16(0).ToString();


        }
      }
      catch (Exception err)
      {
        Response.Write(err.Message);
      }
      finally
      {
        con.Close();
        con.Dispose();
        cmd.Dispose();
      }
      Response.Write(val);
    }
  }


Answers (2)