线程在水晶报表中被异常终止 [英] Thread was being aborted exception in crystal reports

查看:502
本文介绍了线程在水晶报表中被异常终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们用来将报表导出为PDF的下面的代码。

  Response.Buffer = true; 
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType =application / pdf;
myReportDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat,Response,true,Session [ReportName]。ToString());
Response.Flush();
Response.Close();

请帮助我解决此异常。

解决方案

SAP 解释说:



原因


$ b

问题已在问题报告ID ADAPT00765364 下识别并记录。
错误可能是因为 ExportToHttpResponse()方法中使用了 Response.End()

这是一个已知的问题, Reponse.End()导致线程中止。这是设计。

有关详细信息,请参见 Microsoft KB312629文章。 / p>

解决方法



  .... 
try
{
reportDocument.ExportToHttpResponse(format,Response,true,Page.Title);
}
catch(System.Threading.ThreadAbortException)
{
}
....



分辨率



您可以编写自己的代码,将Crystal报表直接导出到浏览器, PDF,Word,Excel等。您必须确保使用适当的内容类型。



示例代码将Crystal Report以PDF格式导出到网络浏览器

  try 
{
boReportDocument.Load(Server.MapPath(@MyReport.rpt));
System.IO.Stream oStream = null;
byte [] byteArray = null;
oStream = boReportDocument.ExportToStream(ExportFormatType.PortableDocFormat);
byteArray = new byte [oStream.Length];
oStream.Read(byteArray,0,Convert.ToInt32(oStream.Length - 1));
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType =application / pdf;
Response.BinaryWrite(byteArray);
Response.Flush();
Response.Close();
boReportDocument.Close();
boReportDocument.Dispose();

}
catch(Exception ex)
{
string s = ex.Message;
}


We were getting the Thread was being aborted Exception while exporting a report into PDF.

The below code we were using for export a report into PDF.

                    Response.Buffer = true;
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.ContentType = "application/pdf";
                    myReportDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Session["ReportName"].ToString());
                    Response.Flush();
                    Response.Close();

Please help me how to resolve this exception.

解决方案

SAP explains that:

Cause

The issue has been identified and logged under Problem Report ID ADAPT00765364. The error is likely caused because Response.End() is used inside the ExportToHttpResponse() method.
It is a known issue that Reponse.End() causes the thread to abort. This is by design.
See Microsoft KB312629 Article for more info.

Workaround

....
 try
   {
   reportDocument.ExportToHttpResponse(format, Response, true, Page.Title);
   }
 catch (System.Threading.ThreadAbortException)
   {
   }
....

Resolution

You can write your own code to export a Crystal Report directly to the browser in a format such as PDF, Word, Excel, etc. You must make sure you use the appropriate content type.

Sample code to export Crystal Report to web browser as PDF

try
{
 boReportDocument.Load(Server.MapPath(@"MyReport.rpt"));
 System.IO.Stream oStream = null;
 byte[] byteArray = null;
 oStream = boReportDocument.ExportToStream (ExportFormatType.PortableDocFormat);
 byteArray = new byte[oStream.Length];
 oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
 Response.ClearContent();
 Response.ClearHeaders();
 Response.ContentType = "application/pdf";
 Response.BinaryWrite(byteArray);
 Response.Flush();
 Response.Close();
 boReportDocument.Close();
 boReportDocument.Dispose();

}
catch (Exception ex)
{
 string s = ex.Message;
}

这篇关于线程在水晶报表中被异常终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆