将.rdl文件转换为pdf格式时出错

时间:2010-05-27 05:06:56

标签: sql-server reporting-services

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

堆栈跟踪如下: -

 at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Microsoft.Reporting.WebForms.LocalReport.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at SaltlakeSoft.APEX2.Controllers.TestPageController.RenderReport() in E:\Documents and Settings\Administrator\Desktop\afetbuild15thmayapex2\apex2\Controllers\TestPageController.cs:line 1626
at lambda_method(ExecutionScope , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.c_DisplayClass1.b_0(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters)
at System.Web.Mvc.ControllerActionInvoker.c_DisplayClassa.b_7()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

我使用以下代码: -

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(); 

1 个答案:

答案 0 :(得分:0)

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

我已经看到最多两个嵌套的InnerExceptions(即thisException.InnerException.InnerException)并且可能有更多,所以你可能想要在你的进程上设置一个循环以从最内层的异常中获取Message。