Problem description:
I'm having trouble slowing down reporting with a "large" volume of data in Report Viewer 2015.
When I generate a report with 5600 records in pdf format, it takes about 35 seconds to display the report, and although I know that reporting 5000 items is not very common, we use filters that reduce the number of reports records, there is the fact that in other formats time falls by half, the comparison follows:
- Pdf = [35s, 5603 records]
- Doc = [18s, 5603 records]
- Excel = [16s, 5603 records]
I've already done a good research on the subject and I could see that Report Viewer actually takes longer to generate pdf files, but I wonder if anyone has seen something like this and could give me suggestions of possible improvements to try decrease this time.
Demo report:
Code:
Note:Mycodeistoolargetoputhere,butI'llputthepartsIthinkaremoreimportant.
ReportMethodintheMVCController:
publicvirtualIActionResultReport(stringfiltros){varconfiguracaoRelatorio=newConfiguracaoRelatorio<TModel>(filtros,GetDados(filtros));vargeradorDeRelatorio=newGeradorDeRelatorio<TModel>(configuracaoRelatorio);varreportResult=geradorDeRelatorio.Gerar();returnnewFileContentResult(reportResult.FileContents,reportResult.ContentType);}
GeneratemethodoftheReportGeneratorclass:
publicReportResultGerar(){using(varrelat=newLocalReport()){relat.SetBasePermissionsForSandboxAppDomain(newPermissionSet(PermissionState.Unrestricted));//Parapoderutilizarimagensexternasrelat.EnableExternalImages=true;varrelatorioBaseXML=newRelatorioBaseXML(ConfiguracaoRelatorio.CaminhoArquivoBaseRelatorio);//Outrasconfiguraçõestambémsãorealizadasaqui,maseuoculteiparanãoficarmuitoextenso.relatorioBaseXML.ConfigurarFonteRdlc(ConfiguracaoRelatorio.FonteTipo,ConfiguracaoRelatorio.FonteTamanho);using(varstringReader=newStringReader(relatorioBaseXML.GetXml().OuterXml)){relat.LoadReportDefinition(stringReader);}//Passandoosdadosparaorelatóriorelat.DataSources.Add(newReportDataSource{Name="dsTabela",
Value = ConfiguracaoRelatorio.Dados
});
relat.SetParameters(new ReportParameter[] {
new ReportParameter("NomeEmpresa", ConfiguracaoRelatorio.EmpresaNome, true),
new ReportParameter("TituloRelatorio", ConfiguracaoRelatorio.TituloRelatorio, true),
new ReportParameter("NomeDesenvolvedor", ConfiguracaoRelatorio.DesenvolvedorNome, true),
new ReportParameter("ParametrosRelatorio", ConfiguracaoRelatorio.Parametros, true),
new ReportParameter("LogotipoEmpresa", new Uri(ConfiguracaoRelatorio.CaminhoLogoBaseRelatorio).AbsoluteUri)
});
Warning[] warnings;
string[] streams;
byte[] bytes;
string mimeType;
string encoding;
string fileNameExtension;
string reportType = null;
switch (ConfiguracaoRelatorio.Filtros.FormatoRelatorio)
{
case FormatoRelatorio.PDF:
reportType = "PDF";
break;
case FormatoRelatorio.Excel:
reportType = "Excel";
break;
case FormatoRelatorio.Word:
reportType = "Word";
break;
default:
reportType = "PDF";
break;
}
var deviceInfo =
"<DeviceInfo>" +
"<OutputFormat>" + reportType + "</OutputFormat>" +
"</DeviceInfo>";
//Renderizando o relatório
bytes = relat.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
return new ReportResult(bytes, mimeType);
}
}