byte[] renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
protected void BtnExcel_Click(object sender, EventArgs e)
{
var lstClient = GetDatosInfome();
Session["lstClient"] = lstClient;
if (lstClient.Count <= 0) return;
var localReport = new LocalReport
{
ReportPath = HttpContext.Current.Server.MapPath("~/Informes/Clientes/ListadoClientes.rdlc")
};
var reporteDataSourceClientes = new ReportDataSource("ClientesInforme", lstClient);
localReport.DataSources.Add(reporteDataSourceClientes);
Informe.GeneraInforme(TipoSalida.Excel, localReport, "Listado Clientes");
}
protected void BtnPdf_Click(object sender, EventArgs e)
{
var lstClient = GetDatosInfome();
Session["lstClient"] = lstClient;
if (lstClient.Count <= 0) return;
var localReport = new LocalReport { ReportPath = HttpContext.Current.Server.MapPath("~/Informes/Clientes/ListadoClientes.rdlc") };
var reporteDataSourceClientes = new ReportDataSource("ClientesInforme", lstClient);
localReport.DataSources.Add(reporteDataSourceClientes);
Informe.GeneraInforme(TipoSalida.Pdf, localReport, "Listado Clientes");
}
public static void GeneraInforme(TipoSalida tipoSalida, LocalReport localReport, string tituloInforme)
{
try
{
string reportType = tipoSalida.ToString();
string mimeType;
string encoding;
string fileNameExtension;
Warning[] warnings;
string[] streams;
string deviceInfo = "<DeviceInfo><SimplePageHeaders>False</SimplePageHeaders></DeviceInfo>";
// TODO: Buscar Solución OutOfMemoryException
// Problemas de OutOfMemory
byte[] renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
TransmitReport(tipoSalida, tituloInforme, fileNameExtension, renderedBytes);
}
catch (LocalProcessingException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
private static void TransmitReport(TipoSalida tipoSalida, string tituloInforme, string fileNameExtension, byte[] renderedBytes)
{
HttpContext.Current.Response.Clear();
switch (tipoSalida)
{
case TipoSalida.Pdf:HttpContext.Current.Response.ContentType = "application/pdf";
break;
case TipoSalida.Excel:HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
break;
}
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + tituloInforme + "." + fileNameExtension);
HttpContext.Current.Response.BinaryWrite(renderedBytes);
HttpContext.Current.Response.End();
//HttpContext.Current.Response.Flush();
//HttpContext.Current.Response.Close();
}
Use ReportServer select * from ExecutionLog3 order by TimeStart DESC
--
Has recibido este mensaje porque estás suscrito al grupo "AltNet-Hispano" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispan...@googlegroups.com.
Para publicar en este grupo, envía un correo electrónico a altnet-...@googlegroups.com.
Visita este grupo en http://groups.google.com/group/altnet-hispano.
Para acceder a más opciones, visita https://groups.google.com/d/optout.
localReport.DataSources.Add(reporteDataSourceClientes);
...
2 – “The ReportViewer control, which processes .rdlc files, ignores the <Query> element of RDL. If a report definition contains a query, the control will not process it. So A client report definition (.rdlc) file will only contain a query if it originated as a .rdl file.” MSDN said.
3 – DataSet and Data Source which used in RDLC and RDL files are totally different. RDLC (Client reports) use DataSet which actually is a DataTable and RDL (SQL Server Report) use DataSource which consist of a Data Source (actually connection String). Some Credential Information which used to access Database mentioned in Data Source and finally a SQL Command (StoreProcedure – Function …) or a Query which retrieve data from Database.
En PRO, en el mismo servidor
en versión v2 de la aplicación (https://server/v2/Ventas.aspx da error OutOfMemoryException
en versión v1, vS 2008 , .NET 3.5, https://server/v1/Ventas.aspx Genera bien informe en PRO
v1 >- APPPOOL "xxx2001Pool" (MgdVersion:v2.0,MgdMode:Classic,state:Started) Cuenta: domain\MyAppPool
v2- >APPPOOL "xxx2015Pool" (MgdVersion:v4.0,MgdMode: Classic,state:Started). Cuenta: ApplicationPoolIdentity.
Mismo código en ambos…
public class InformeVentas : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
LocalReport localReport = new LocalReport
{
ReportPath = HttpContext.Current.Server.MapPath("~/Informes/InformeVentas.rdlc")
};
List<TablaEvolucionValorAnterior> listaPolizas = DatosGrafica.GetTablaEvolucionPolizasVentas(Convert.ToInt32(context.Request["empresa"]), Convert.ToInt32(context.Request["mediador"]));
ReportDataSource reportDataSourcePolizas = new ReportDataSource("TablaEvolucionVentasPolizas", listaPolizas);
localReport.DataSources.Add(reportDataSourcePolizas);
List<TablaEvolucionValorAnterior> listaPrimas = DatosGrafica.GetTablaEvolucionPrimasVentas(Convert.ToInt32(context.Request["empresa"]), Convert.ToInt32(context.Request["mediador"]));
ReportDataSource reportDataSourcePrimas = new ReportDataSource("TablaEvolucionVentasPrimas", listaPrimas);
localReport.DataSources.Add(reportDataSourcePrimas);
List<TablaRamosVentas> listaRamos = DatosGrafica.GetTablaRamosVentas(Convert.ToInt32(context.Request["empresa"]), Convert.ToInt32(context.Request["mediador"]));
ReportDataSource reportDataSourceRamos = new ReportDataSource("TablaRamosVentas", listaRamos);
localReport.DataSources.Add(reportDataSourceRamos);
List<ReportParameter> parameters = new List<ReportParameter>
{
new ReportParameter("FechaDatos", DatosGrafica.GetFechaActualizacionDatos().ToShortDateString())
};
localReport.SetParameters(parameters);
Informe.GeneraInforme((TipoSalida)Convert.ToInt32(context.Request["tipoSalida"]), localReport, "InformeVentas");
}
public static void GeneraInforme(TipoSalida tipoSalida, LocalReport localReport, string tituloInforme)
{
string reportType = tipoSalida.ToString();
string mimeType;
string encoding;
string fileNameExtension;
Warning[] warnings;
string[] streams;
string deviceInfo = "<DeviceInfo><SimplePageHeaders>False</SimplePageHeaders></DeviceInfo>";
byte[] renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
HttpContext.Current.Response.Clear();
switch (tipoSalida)
{
case TipoSalida.Pdf:
HttpContext.Current.Response.ContentType = "application/pdf";
break;
case TipoSalida.Excel:
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
break;
}
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + tituloInforme + "." + fileNameExtension);
HttpContext.Current.Response.BinaryWrite(renderedBytes);
HttpContext.Current.Response.End();
}
Una llamada a GC.Collect() me ha funcionado como workaround, pero es una buena práctica?
http://stackoverflow.com/questions/6053036/diagnosing-net-outofmemoryexception-when-generating-reports
En algún caso, comentan que hay que realizar la llamada a GC.Collect() dos veces:
http://stackoverflow.com/questions/3829928/under-what-circumstances-we-need-to-call-gc-collect-twice
En foros y MSDN hablan de ciertos cambios en .NET 4.5 en relación al Garbage Collector:
More common reason to get System.OutOfMemoryException is due to memory fragmentation - there is no large enough continuous space in memory. You should install a memory profiler to verify that - then you can also try to find out which objects take up the memory.
If possible, you might want to test .NET 4.5 - Microsoft has made changes to the Garbage Collector so that LOH is automatically defragmented for server applications (such as IIS): http://blogs.msdn.com/b/dotnet/archive/2011/10/04/large-object-heap-improvements-in-net-4-5.aspx
performanceScenario ?
http://www.asp.net/aspnet/overview/aspnet-and-visual-studio-2012/whats-new#_Toc_perf
http://docs.sitefinity.com/recommended-environment-settings
Aún tengo cierta confusión al respecto.
--
renderer.Generate(format, title);
}
}
catch (Exception ex)
{
OutOfMemoryHandling(ex, (title + " - " + reportPath), outOfMemoryHandling, () =>
{
DoGenerateRDLC(reportPath, title, format, parametros, false);
});
internal static void OutOfMemoryHandling(Exception ex, string tituloInforme, bool outOfMemoryHandling, Action actionRetryIfExceptionIsOutOfMemory)
{
var msg = "Error " + ex.Message + " para Informe " + tituloInforme;
msg += ". Retry Handling OutOfMemory " + outOfMemoryHandling;
LoggerReporting.Trace(msg);
if (!outOfMemoryHandling) throw ex;
var okOutOfMemory = DoOutOfMemoryHandling(ex);
if (okOutOfMemory)
{
actionRetryIfExceptionIsOutOfMemory();
return;
}
throw ex;
}
private static bool DoOutOfMemoryHandling(Exception ex)
{
var exceptionCurrent = ex;
if (exceptionCurrent is LocalProcessingException)
{
exceptionCurrent = ex.InnerException;
while (exceptionCurrent.InnerException != null)
exceptionCurrent = exceptionCurrent.InnerException;
}
if (exceptionCurrent is OutOfMemoryException)
{
GC.Collect();
//GcHelper.AggressivelyCollect();
return true;
}
return false;
<gcServer enabled="true"/>--
--
If you are the administrator for a server that is shared by hosting several small Web sites, you can optimize performance and increase site capacity by adding the following gcTrimCommitOnLowMemory setting to the runtime node in the Aspnet.config file in the .NET Framework directory:
<gcTrimCommitOnLowMemory enabled="true|false"/>
Workarounds:
You can compile your application in Net 3.5 and avoid all performance problems with the Report Viewer (which is multi- targeted for 3.5 and 4.0). If you do so, DO NOT use the viewer option "ExecuteReportInSandboxDomain" since that will bring back the problem (duh). You are then running in the current AppDomain, could have memory leak problems with an ASPNET application, and of course abandon any use of other Net 4.0 features. Loading the old viewer (can be done) does allow the use of the sandbox domain but would possibly bring back the problem of the sandbox domain not unloading properly. It's a no win situation I think.
Alternatively you can stay with Net 4.0 but force the use of´ legacy CAS security.
I experienced the same problem in .NET 4.5 in ASP.NET based application with heavy use of dynamic types for serialization and deserialization. So I could not use < trust legacyCasModel="true" level="Full"/>,
I managed to create another workaround based on custom CAS security settings in separated AppDomain directly in original application without the need to deploy reports to RS, or to create some stand alone application/web service based on .NET3.5 or settings mentioned in previous replies.
My reports went down from 18s to 2s
Local report processing requires full trust for an ASP.Net 4 site, at least if there are any expressions or parameters. Remote report processing (with the reports hosted on a SQL Server Report Services server) works in medium trust even for reports with expressions and parameters.
http://blogs.msdn.com/b/brianhartman/archive/2010/02/18/expression-evaluation-in-local-mode.aspx
The ReportViewer in VS 2010 is a multi-targeted assembly. That means that is can be loaded into a .Net 3.5 or a .Net 4.0 application. When running under .Net 3.5, all of the same rules and methods noted above are applicable. However, the CLR security team made changes to code access security in .Net 4.0, so there are corresponding changes in the ReportViewer as well: