Welcome to MSDN Blogs Sign in | Join | Help

SQL Developer - Connecting Databases

This BLOG is for the Developer community. It will contain details like Troubleshooting common SQL Server connectivity issues from any front end application, XML / MSXML related stuffs, SQL Server Reporting Services configuration to Design of reports etc.
Getting System.OutOfMemoryException when using ReportViewer contol in Local mode

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,

== VB.NET

If Session.Count > 0 Then

For i As Integer = 0 To Session.Count - 1

If Session(i).GetType().ToString() = "Microsoft.Reporting.WebForms.ReportHierarchy" Then

Session.RemoveAt(i)

End If

Next

End If

== C#,

if(Session.Count > 0)

{

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

{

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

{

Session.RemoveAt(i);

}

}

}

Posted: Friday, July 18, 2008 12:23 PM by selvar
Filed under:

Comments

jeff said:

it made absolutely no difference. It dies even on a single report if your recordset is substantially large. The problems are much deeper-rooted than the session.

# April 7, 2009 1:13 PM

selvar said:

The above scenario is one such and Out of memory can pop up due to different reasons. Client side reports are specifically made for lighter execution. If your report is going to have a huge amount of dataset or having too much of complex expression then, RDLC is not a recommended one. Server side reports can take much additional loads and Reporting Service 2008 has a new, optimized processing engine which is highly efficient.

More details:

http://blogs.msdn.com/brianhartman/archive/2008/12/05/sql-server-2008-and-the-reportviewer-controls.aspx

# May 7, 2009 2:00 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker