0
votes

I an generating reports using SQL Server reporting services. I have generated a report and have put .rdl report file in the "E" drive. Now, when I am going to render the .rdl report file into pdf format,I am getting the exception : - "An error occurred during local report processing."

The stack trace is follows : -

 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)

I am using the following code : -

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

1 Answers

0
votes

You'll need to wrap your code in a try/catch block, and look at the exception's InnerException, in order to see the details of why the report rendering failed. There could be a hundred different reasons, from unexpected data in the query results to incorrect page margins, or even an exception in an expression that is embedded in the report.

I have seen up to two nested InnerExceptions (i.e. thisException.InnerException.InnerException) and it may be possible to have more, so you'll probably want to put a loop on your process to grab the Message from the innermost exception.