【发布时间】:2023-03-13 06:06:01
【问题描述】:
有什么方法可以提高本地报告的性能,或者如果没有的话,还有其他方法吗?下面将 rdlc 转换为 pdf 的当前代码。一段时间以来一直在寻找解决方案,但普遍的共识似乎是它的速度很慢,感谢您的帮助。
public byte[] genReportBytes(int id, string fromm, string too, string filetype)
{
reportDetails repD = new reportDetails();
repD = getOneReport(id);
LocalReport report = new LocalReport();
if (fromm != null)
repD.ParametersCommandLine = "@startdate=" + fromm;
if (too != null)
repD.ParametersCommandLine += " @enddate=" + too;
string RDLCPath = ConfigurationManager.AppSettings["RDLCPath"];
string ReportOutputPath = ConfigurationManager.AppSettings["ReportOutputPath"];
string RDLCName = repD.RDLCName;
RDLCPath += @"\" + RDLCName;
report.ReportPath = RDLCPath;
string sqlGet = repD.SQLOfReport;
report.DataSources.Add(new ReportDataSource(repD.DatasetName, getReportData(sqlGet, repD.ParametersCommandLine)));
// export to byte array
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
string deviceInf = "";
byte[] bytes;
string extension;
if (filetype == "pdf")
{
deviceInf = "<DeviceInfo><PageHeight>8.5in</PageHeight><PageWidth>11in</PageWidth><MarginLeft>0in</MarginLeft><MarginRight>0in</MarginRight></DeviceInfo>";
//fileName = ReportOutputPath + @"\" + repD.NameOfOutputPDF + ".PDF";
bytes = report.Render("pdf", deviceInf, out mimeType, out encoding, out filenameExtension,
out streamids, out warnings);
}
else
{
//fileName = ReportOutputPath + @"\" + repD.NameOfOutputPDF + ".XLS";
bytes = report.Render(
"Excel", null, out mimeType, out encoding,
out extension,
out streamids, out warnings);
}
return bytes;
}
【问题讨论】:
-
这两行
ParametersCommandLine让我怀疑您的代码可能容易受到SQL Injection 的攻击。你的getReportData方法是什么样的? -
如果您在基于 .NET 4.5 in ASP.NET 的应用程序中使用而不大量使用 动态类型进行序列化和反序列化。也许可以使用
<trust legacyCasModel="true" level="Full"/> -
@Kiquenet 代码审查代表审查工作代码,也可以要求性能改进。很好的例子:codereview.stackexchange.com/questions/104879/…
-
@chillworld 不错,性能改进不一样性能问题?
-
Adrian Nichols 在 github.com/AdrianNichols/ssrs-non-native-functions/blob/…
Keys中有一个帮助代码:RenderReportToMemoryAsPDFInAnotherAppDomain方法和ReportHelperInAppDomain类