Exception of type System.OutOfMemoryException is thrown

K

karups

Hi,
There are several pages that occasionally start throwing
System.OutOfMemoryException and "The type initializer for
"Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataCommandFailedEvent
exception."


The problem goes away after iisreset .

- Actually on Excel Exporting this error happens and stops all the
applications in the server
- It exceeds more than 1GB size, i hope so in server
-

How to solve this problem? How to reduce size of Dataset when exporting
to excel file?
Help me out in this...
Thanks in advance

-karups
 
M

Marc Gravell

You may wish to clarify what exactly your code is doing... it isn't entirely
clear from the post.

Initial thoughts:
* Are you using Excel directly on the server? Yup, that might not scale so
well...
* Reduce the size of the DataSet => work with less data...
* ...or, work with a "streaming" approach rather than an "in memory"
approach - i.e. it loads a record ([or a few, or dozens, or hundreds, but
not millions] at a time) from the source, processes (writes?) that record /
those records, and *then* moves on. Think IDataReader, Stream, etc

Maybe if you can clarify what you are trying to achieve somebody can suggest
a better approach.

Marc
 
K

karups

My application will have a fetch button.
As soon as we click the fetch button..It calls a Stored Procedure.
The stored procedure will return a dataset back(huge on with rows 25000
and col:52)...
I export this dataset to excel using this code

Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename="+filename+".xls");
Response.Charset = "";
this.EnableViewState=false;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
DataGrid myDataGrid=new DataGrid();
myDataGrid.DataSource=dsReport.Tables[1];
myDataGrid.DataBind();
myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

While doing this i get the OutOfMemoryException..
 
K

karups

My application will have a fetch button.
As soon as we click the fetch button..It calls a Stored Procedure.
The stored procedure will return a dataset back(huge on with rows 25000
and col:52)...
I export this dataset to excel using this code

Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename="+filename+".xls");
Response.Charset = "";
this.EnableViewState=false;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
DataGrid myDataGrid=new DataGrid();
myDataGrid.DataSource=dsReport.Tables[1];
myDataGrid.DataBind();
myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

While doing this i get the OutOfMemoryException..
 
G

Guest

It seems to be well known issue, but the solution is not so trival
Obviously the reason is that your managed heap is overly fragmented that FW
couldn't find free 64mb heap segment to allocate memory.

There are several descriptions in the net about how to investigate this
problem, especially Tess blog (MS escalation engineer)
I recomend to read this recend article
http://msdn.microsoft.com/msdnmag/issues/06/11/CLRInsideOut/default.aspx that
describes your aspect of problem

--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
K

karups

Thank you.I read the article,That was useful information.
But can you tell me a way to rectify in my application if possible..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top