【问题标题】:Error while rendering .rdl file into pdf format将 .rdl 文件渲染为 pdf 格式时出错
【发布时间】:2011-02-24 12:08:44
【问题描述】:

我使用 SQL Server 报告服务生成报告。我已经生成了一份报告并将 .rdl 报告文件放在“E”驱动器中。现在,当我将 .rdl 报告文件呈现为 pdf 格式时,我收到异常:-“本地报告处理期间发生错误。”

堆栈跟踪如下:-

 在 Microsoft.Reporting.WebForms.LocalReport.InternalRender(字符串格式,布尔值 allowInternalRenderers,字符串 deviceInfo,CreateAndRegisterStream createStreamCallback,Warning[]& 警告)
在 Microsoft.Reporting.WebForms.LocalReport.InternalRender(字符串格式,布尔值在 Microsoft.Reporting.WebForms.LocalReport.Render(字符串格式,字符串设备信息,字符串和 mimeType,字符串& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
在 SaltlakeSoft.APEX2.Controllers.TestPageController.RenderReport() 在 E:\Documents and Settings\Administrator\Desktop\afetbuild15thmayapex2\apex2\Controllers\ TestPageController.cs:line 1626
在 lambda_method(ExecutionScope , ControllerBase , Object[] )
在 System.Web.Mvc.ActionMethodDispatcher.c_DisplayClass1.b_0(ControllerBase 控制器, Object[] 参数)
在 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object[] 参数)
在 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext 控制器上下文,IDictionary2 参数)
在 System.Web.Mvc.ControllerActionInvoker .InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 参数)
在 System.Web.Mvc.ControllerActionInvoker.c_DisplayClassa.b_7()
在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func `1 续)

我正在使用以下代码:-

LocalReport report = new LocalReport();

report.ReportPath = @"E:\Report1.rdl";

List<Employee> employeeCollection = empRepository.FindAll().ToList();

ReportDataSource reportDataSource = new ReportDataSource("dataSource1",employeeCollection);

report.DataSources.Clear();

report.DataSources.Add(reportDataSource);

report.Refresh();

string reportType = "PDF";

string mimeType;

string encoding;

string fileNameExtension;

string deviceInfo ="<DeviceInfo>" +"<OutputFormat>PDF</OutputFormat>" +
    "<PageWidth>8.5in</PageWidth>" + "<PageHeight>11in</PageHeight>" +
    "<MarginTop>0.5in</MarginTop>" +"<MarginLeft>1in</MarginLeft>" + 
    "<MarginRight>1in</MarginRight>" +"<MarginBottom>0.5in</MarginBottom>" +
    "</DeviceInfo>";

Warning[] warnings;

string[] streams;

byte[] renderedBytes;           

renderedBytes = report.Render(reportType,deviceInfo,out mimeType,out encoding, out fileNameExtension, out streams, out warnings);

Response.Clear();

Response.ContentType = mimeType;

Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);

Response.BinaryWrite(renderedBytes);

Response.End(); 

【问题讨论】:

    标签: sql-server reporting-services


    【解决方案1】:

    您需要将代码包装在 try/catch 块中,并查看异常的 InnerException,以便查看报告呈现失败的详细信息。可能有一百种不同的原因,从查询结果中的意外数据到不正确的页边距,甚至是报表中嵌入的表达式中的异常。

    我已经看到了最多两个嵌套的 InnerExceptions(即thisException.InnerException.InnerException),并且可能有更多,因此您可能希望在您的进程上放置一个循环以从最里面的异常中获取消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      相关资源
      最近更新 更多