Click here to Skip to main content
16,016,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to display XML from Oracle in browser. It is working well in my local machine (Windows XP). But it is throwing me system. BadImageexception after deploying the code on IIS7.0
I am using providerName="System.Data.OleDb"
Please help me where I am doing wrong.

CODE:
C#
private void DisplayXML(Int16 id)
       {
           string connectionString = WebConfigurationManager.ConnectionStrings["oracledev"].ConnectionString;
           using (OracleConnection con = new OracleConnection(connectionString))
           {
               con.Open();
               OracleCommand cmd = new OracleCommand();
               cmd.Connection = con;
               cmd.CommandType = CommandType.Text;
               cmd.CommandText = "SELECT xml FROM TABSDORDERAUDITLOG  WHERE ID=" + id;

               var xmldata = Convert.ToString(cmd.ExecuteScalar());
               System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
               Byte[] bytes = encoding.GetBytes(xmldata);
               using (MemoryStream memStream = new MemoryStream())
               {
                   memStream.Write(bytes, 0, bytes.Length);
                   Response.Clear();
                   Response.ContentEncoding = Encoding.UTF8;
                   Response.AppendHeader("Content-Disposition", "");
                   Response.AppendHeader("Content-Length", bytes.Length.ToString());
                   Response.ContentType = "application/octet-stream";
                   Response.BinaryWrite(bytes);
               }
               if (con.State == ConnectionState.Open)
                   con.Close();
           }
       }
   }


Error Message:
Server Error in '/QueryUIApp' Application.
--------------------------------------------------------------------------------
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:

[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]
Oracle.DataAccess.Client.OpsTrace.GetRegTraceInfo(UInt32& TrcLevel, UInt32& StmtCacheSize) +0
Oracle.DataAccess.Client.OraTrace.GetRegistryTraceInfo() +104
Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString) +97
QueryAuditUI.SDAuditMessage.DisplayXML(Int16 id) +109
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
Posted
Updated 6-Sep-11 3:56am
v2

1 solution

Hi,

Could you try to add this in your code behind.

 protected void Page_PreRender(object sender, EventArgs e)
{
  HtmlMeta metatag = new HtmlMeta();
  metatag.Attributes.Add("http-equiv", "X-UA-Compatible");
  metatag.Attributes.Add("content", "ID=EmulateIE7");
  metatag.Attributes.Add("content", "IE=8");
  metatag.Attributes.Add("content", "IE=edge");
  Page.Header.Controls.AddAt(0, metatag);
}


Please let me know by comment if it is working or not.
I am not try on this case on such...

Regards,

Algem
 
Share this answer
 
Comments
eskumar 7-Sep-11 6:35am    
I am not sure if the issue is with my code. Because the same code is working when i deployed in QA machine..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900