An error occurred while processing the report. -RLDC Reports in ASP.NET MVC

I have this action for creating reports:

public ActionResult Report(string id) { LocalReport lr = new LocalReport(); string path = Path.Combine(Server.MapPath("~/Report"), "Person.rdlc"); if (System.IO.File.Exists(path)) { lr.ReportPath = path; } else { return View("Index"); } List<Person> cm = new List<Person>(); var viewModel = new PersonIndexData(); viewModel.People= db.Person .Include(k => k.Groups) .OrderBy(k => k.Name); cm = viewModel.People.ToList(); ReportDataSource rd = new ReportDataSource("PersonDataSet", cm); lr.DataSources.Add(rd); string reportType = id; string mimeType; string encoding; string fileNameExtension; Warning[] warnings; string[] streams; byte[] renderedBytes; renderedBytes = lr.Render( reportType, null, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); return File(renderedBytes, mimeType); } 

When I call this action as follows: (mysite / person / report / pdf), I get this exception:

An error occurred while processing the report. Indication of this line:

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

Can you tell me why I get this exception in this code? This makes no mistake, and the exception is not very explainable. First I use the EF code. Thanks.

+2
source share
3 answers

Are you trying to do this after adding a TableAdapter? It works great for me.

 public FileResult Report(string id) { PersonTableAdapter ta = new PersonTableAdapter(); PersonDataSet ds = new PersonDataSet(); //for avoiding "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." error ds.Person.Clear(); ds.EnforceConstraints = false; ta.Fill(ds.Person, id); //You might customize your data at this step ie applying a filter ReportDataSource rds = new ReportDataSource(); rds.Name = "ReportingDataSet"; rds.Value = ds.Person; ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer(); rv.ProcessingMode = ProcessingMode.Local; rv.LocalReport.ReportPath = Server.MapPath("~/Report/Person.rdlc"); // Add the new report datasource to the report. rv.LocalReport.DataSources.Add(rds); rv.LocalReport.EnableHyperlinks = true; rv.LocalReport.Refresh(); byte[] streamBytes = null; string mimeType = ""; string encoding = ""; string filenameExtension = ""; string[] streamids = null; Warning[] warnings = null; streamBytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); return File(streamBytes, mimeType, "Person" + "_" + id + ".pdf"); } 

Hope this helps ...

+2
source

I'm not sure which one will help you, so I list them as:

  • Try removing the data source from the Report menu and then adding it again
  • Before proceeding, check the Render function of the requirement , so you can check the values โ€‹โ€‹of the in and out parameters.
  • Try to see some examples around LocalReporter to learn more about how to use this tool.

And finally, the line that throws the exception does not match the main code, since you put null instead of deviceInfo ! .

+2
source

My rdlc solution is based on ReportViewer.

  byte[] bytes = null; string attachmentName = string.Empty; Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; /*GetReportDataSources(logicResult, spec);*/ var reportPath = GetReportExecutionPath(); ReportViewer viewer = new ReportViewer(); /*viewer.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(LocalReport_SubreportProcessing);*/ viewer.LocalReport.ReportPath = reportPath; /*viewer.LocalReport.SetParameters(parameters);*/ viewer.LocalReport.EnableExternalImages = true; viewer.RefreshReport(); viewer.LocalReport.DisplayName = "displayName"; bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings); 

/ * some logic * /

  return new StreamResponse(() => { var pdfOutput = new MemoryStream(bytes); pdfOutput.Seek(0, SeekOrigin.Begin); return pdfOutput; }, "application/pdf").WithHeader("Content-Disposition", "attachment; filename=" + attachmentName); 

You also need to add the path to the reports and data sources (my solution is complicated, and I use LocalReport_SubreportProcessing for this).

PS Using rdlc with ASP.MVC has 1 problem. You need to install "Identity = LocalSystem" in the ISS application pool, which is normal on the intranet but not on the Internet.

+1
source

Source: https://habr.com/ru/post/1396680/


All Articles