RDLC LocalReport导出到Excel确实很慢

我们有一个Asp.Net页面,它针对后端的Oracle数据库运行RDLC Local报告,导出到Excel电子表格时速度非常慢。 我做了一些调查并确定查询本身不应该受到责备 – 我可以使用SQL Developer直接针对Oracle运行查询,并在大约5秒内将结果导出到Excel,但是当我通过asp运行它时。网页和ReportViewer控件大约需要3分钟才能返回。

有没有人有任何建议,为什么这么慢? 查询返回大约8000行,每行约30列,所以它不是一个很小的结果集,但它也不是很大。 关于如何优化报告的任何建议都将不胜感激。

我正在使用Microsoft.ReportViewer.WebForms版本10.0.0.0,有谁知道v11是否有性能改进?

编辑:尝试过ReportViewer v11,速度没有提高。

如果您在报告中有分组。 从.NET 4开始,当删除旧CAS时,本地处理的RDLC报告需要花费大量时间来执行动态分组或动态filter。 现有的讨论与此https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6d89e2ce-3528-465f-9740-7e22aa7b7aae/slow-performance-with-dynamic-grouping-and-有关。的ReportViewer -在本地模式?论坛= sqlreportingservices
我发现他们中最好的解决方案是,
1.创建一个新的.NET 3.5库项目并创建一个执行Report实际处理的文件。

using Microsoft.Reporting.WebForms; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; //As you would expect, the new assembly WebReportviewer.FullTrustReportviewer //all it does is just run the report. that's it. here is the code, it should be in a separated project: namespace WebReportviewer { [Serializable] public class FullTrustReportviewer : MarshalByRefObject { private ReportViewer FullTrust; public FullTrustReportviewer() { FullTrust = new ReportViewer(); FullTrust.ShowExportControls = false; FullTrust.ShowPrintButton = true; FullTrust.ShowZoomControl = true; FullTrust.SizeToReportContent = false; FullTrust.ShowReportBody = true; FullTrust.ShowDocumentMapButton = false; FullTrust.ShowFindControls = true; //FullTrust.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing; //FullTrust.LocalReport.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted)); } public void Initialize(string DisplayName, string ReportPath, bool Visible, ReportParameter[] reportParam, string reportRenderFormat, string deviceInfo, string repMainContent, List repSubContent) { FullTrust.LocalReport.DisplayName = DisplayName; FullTrust.LocalReport.ReportPath = ReportPath; //FullTrust.Visible = Visible; //FullTrust.LocalReport.LoadReportDefinition(new StringReader(repMainContent)); FullTrust.LocalReport.SetParameters(reportParam); repSubContent.ForEach(x => { FullTrust.LocalReport.LoadSubreportDefinition(x[0], new StringReader(x[1])); }); FullTrust.LocalReport.DataSources.Clear(); } public byte[] Render(string reportRenderFormat, string deviceInfo) { return FullTrust.LocalReport.Render(reportRenderFormat, deviceInfo); } public void AddDataSources(string p, DataTable datatable) { FullTrust.LocalReport.DataSources.Add(new ReportDataSource(p, datatable)); } public SubreportProcessingEventHandler SubreportProcessing { get; set; } public static void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e) { LocalReport lr = (LocalReport)sender; e.DataSources.Clear(); ReportDataSource rds; if (e.ReportPath.Contains("DataTable2")) { DataTable dt = (DataTable)lr.DataSources["DataTable2"].Value; DataView dv = new DataView(dt); dv.RowFilter = string.Format("Id={0}", e.Parameters["Id"].Values[0]); rds = new ReportDataSource("DataTable2", dv.ToTable()); e.DataSources.Add(rds); } } } } 

2.从现有项目中调用代码

  public static byte[] GeneratePBAReport() { string l_spName = string.Empty; string l_reportPath = string.Empty; var repCol = new List(); var repParCol = new ReportParameter[1]; if (id == "") { l_reportPath = HttpContext.Current.Server.MapPath("~\\.rdlc"); l_spName = ""; } else { l_reportPath = HttpContext.Current.Server.MapPath("~\\.rdlc"); l_spName = ""; } repParCol[0] = new ReportParameter("pID", ""); var ds = new DataSet(); using (var sqlCmd = new SqlCommand(l_spName, new SqlConnection(ConfigurationManager.ConnectionStrings[""].ConnectionString))) { sqlCmd.CommandType = CommandType.StoredProcedure; var sqlParam = new SqlParameter() { Value = "", ParameterName = "" }; sqlCmd.Parameters.Add(sqlParam); sqlCmd.CommandTimeout = 300; using (var sqlAdapter = new SqlDataAdapter(sqlCmd)) { sqlAdapter.Fill(ds); } } var rds = new ReportDataSource(); rds.Name = ""; rds.Value = ds.Tables[0]; //l_report.DataSources.Add(rds); repCol.Add(rds); rds = new ReportDataSource(); rds.Name = ""; rds.Value = ds.Tables[1]; //l_report.DataSources.Add(rds); repCol.Add(rds); rds = new ReportDataSource(); rds.Name = ""; rds.Value = ds.Tables[2]; //l_report.DataSources.Add(rds); repCol.Add(rds); rds = new ReportDataSource(); rds.Name = ""; rds.Value = ds.Tables[3]; //l_report.DataSources.Add(rds); repCol.Add(rds); Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; string deviceInfo; deviceInfo = "True"; return NewDomainReport.Render("PDF", deviceInfo, "-" , l_reportPath, true, repCol, string.Empty, new List(), repParCol); } 

对于真正快速的测试,您可以尝试在文章中提到的web.config中添加CAS。

在ASP Net应用程序中,您可以在web.config文件的system.web部分中使用来获得相同的结果。

如果速度显示出显着的改进,则上述代码的行为将相同。 上述代码的好处是创建一个单独的AppDomain而不是影响整个解决方案。