Getting System.OutOfMemoryException when using ReportViewer contol in Local mode

本文介绍了一种在ASP.NET应用中使用本地模式ReportViewer控件时遇到的内存溢出问题及解决方案。当加载大量数据或使用复杂表达式时,ReportViewer会将报告对象存储在会话中,导致内存压力增加,最终可能引发System.OutOfMemoryException异常。文章提供了一个工作区解决方案,通过在页面加载事件中清理特定类型的会话对象来缓解这一问题。
摘要由CSDN通过智能技术生成

 

PROBLEM:

========

  1.  Consider you've a ASP.NET application that contains Report Viewer control (2005 / 2008) in Local Mode.
  2.  You have an RDLC report file, that loads large amount of data / has lots of expressions. (Both are not recommended in Local mode)
  3.  Everytime you refresh the web page, the Report Viewer stores objects in the session.
  4.  The behaviour of Report Viewer storing objects in the session is by design.
  5.  Each time the report viewer page is refreshed the complete report info object is added to session.
  6.  These objects obviously gets deeply rooted in session and so Garbage collector never collects them untill the complete app unloads itself.
  7.  And that is apparently going to increase the memory pressure in multiple folds, ending up with System.OutOfMemoryException.

RESOLUTION: (Please note: This doesn't guarantee to resolve the exception. The Out of Memory exception can be caused due to different reasons and the below workaround is for one such scenario, which can help to avoid this error to a certain extent.)

===========

== In the page_load event, add this,

 

 

if(Session.Count > 0)

{

for (int i = 0; i < Session.Count; i++)

{

if (Session[i].GetType().ToString() == "Microsoft.Reporting.WebForms.ReportHierarchy")

{

Session.RemoveAt(i);

}

}

}

 

 

source:  http://blogs.msdn.com/selvar/archive/2008/07/18/getting-system-outofmemoryexception-when-using-reportviewer-contol-in-local-mode.aspx

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值