报告处理期间发生错误。 - ASP.NET MVC 中的 RLDC 报告
An error occurred during report processing. -RLDC reporting in ASP.NET MVC
我有生成报告的操作:
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);
}
当我这样调用此操作时:(mysite/person/report/pdf),出现此异常:
An error occurred during report processing.
Indicating this line :
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
你能告诉我为什么我会在这段代码中遇到这个异常吗?它不会给出任何错误,并且异常不是很能解释。我首先使用 EF 代码。谢谢。
我不确定哪一个对你有帮助,所以我列出如下:
- 尝试从“报告”菜单中删除数据源,然后再添加它
再次
- 在操作前检查
Render
函数 requirements,因此您可能需要检查 in
和 out
参数值。
- 尝试在
LocalReporter
周围查看 some examples 以更加了解如何使用此工具。
最后,抛出异常的行与主代码不同,因为你放置 null
而不是 deviceInfo
! 问候。
我的 rdlc 解决方案基于 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);
/*一些逻辑*/
return new StreamResponse(() =>
{
var pdfOutput = new MemoryStream(bytes);
pdfOutput.Seek(0, SeekOrigin.Begin);
return pdfOutput;
}, "application/pdf").WithHeader("Content-Disposition", "attachment; filename=" + attachmentName);
您还需要添加报告路径和数据源(我的解决方案很复杂,我为此使用 LocalReport_SubreportProcessing)。
P.S。将 rdlc 与 ASP.MVC 一起使用有 1 个问题。需要在ISS App Pool上设置"Identity = LocalSystem",内网可以,外网不行
添加TableAdapter后,你试过这样吗?它非常适合我。
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 i.e. 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");
}
希望这对您有所帮助...
我有生成报告的操作:
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);
}
当我这样调用此操作时:(mysite/person/report/pdf),出现此异常:
An error occurred during report processing. Indicating this line :
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
你能告诉我为什么我会在这段代码中遇到这个异常吗?它不会给出任何错误,并且异常不是很能解释。我首先使用 EF 代码。谢谢。
我不确定哪一个对你有帮助,所以我列出如下:
- 尝试从“报告”菜单中删除数据源,然后再添加它 再次
- 在操作前检查
Render
函数 requirements,因此您可能需要检查in
和out
参数值。 - 尝试在
LocalReporter
周围查看 some examples 以更加了解如何使用此工具。
最后,抛出异常的行与主代码不同,因为你放置 null
而不是 deviceInfo
! 问候。
我的 rdlc 解决方案基于 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);
/*一些逻辑*/
return new StreamResponse(() =>
{
var pdfOutput = new MemoryStream(bytes);
pdfOutput.Seek(0, SeekOrigin.Begin);
return pdfOutput;
}, "application/pdf").WithHeader("Content-Disposition", "attachment; filename=" + attachmentName);
您还需要添加报告路径和数据源(我的解决方案很复杂,我为此使用 LocalReport_SubreportProcessing)。
P.S。将 rdlc 与 ASP.MVC 一起使用有 1 个问题。需要在ISS App Pool上设置"Identity = LocalSystem",内网可以,外网不行
添加TableAdapter后,你试过这样吗?它非常适合我。
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 i.e. 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");
}
希望这对您有所帮助...