This is a migrated thread and some comments may be shown as answers.

System.OutOfMemoryException

8 Answers 441 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Juan_Massyn
Top achievements
Rank 1
Juan_Massyn asked on 29 Aug 2008, 11:59 AM
Hi,

Don't know if there is a fix for this, but I get a System.OutOfMemoryException when exporting data to pdf using the RadGrid 5.1.2.0

My stack trace is : 

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
  at Telerik.Apoc.Layout.BorderAndPadding.Clone()
  at Telerik.Apoc.Fo.Flow.TableCell.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.TableRow.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.AbstractTableBody.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.Table.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.Block.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.Flow.Layout(Area area, Region region)
  at Telerik.Apoc.Fo.Flow.Flow.Layout(Area area)
  at Telerik.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
  at Telerik.Apoc.StreamRenderer.Render(PageSequence pageSequence)
  at Telerik.Apoc.Fo.FOTreeBuilder.EndElement()
  at Telerik.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.SystemException: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
  at Telerik.Apoc.Layout.BorderAndPadding.Clone()
  at Telerik.Apoc.Fo.Flow.TableCell.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.TableRow.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.AbstractTableBody.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.Table.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.Block.Layout(Area area)
  at Telerik.Apoc.Fo.Flow.Flow.Layout(Area area, Region region)
  at Telerik.Apoc.Fo.Flow.Flow.Layout(Area area)
  at Telerik.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
  at Telerik.Apoc.StreamRenderer.Render(PageSequence pageSequence)
  at Telerik.Apoc.Fo.FOTreeBuilder.EndElement()
  at Telerik.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SystemException: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at Telerik.Apoc.Layout.BorderAndPadding.Clone()
   at Telerik.Apoc.Fo.Flow.TableCell.Layout(Area area)
   at Telerik.Apoc.Fo.Flow.TableRow.Layout(Area area)
   at Telerik.Apoc.Fo.Flow.AbstractTableBody.Layout(Area area)
   at Telerik.Apoc.Fo.Flow.Table.Layout(Area area)
   at Telerik.Apoc.Fo.Flow.Block.Layout(Area area)
   at Telerik.Apoc.Fo.Flow.Flow.Layout(Area area, Region region)
   at Telerik.Apoc.Fo.Flow.Flow.Layout(Area area)
   at Telerik.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
   at Telerik.Apoc.StreamRenderer.Render(PageSequence pageSequence)
   at Telerik.Apoc.Fo.FOTreeBuilder.EndElement()
   at Telerik.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)]
   Telerik.Apoc.ApocDriver.FireApocError(String message) +78
   Telerik.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader) +628
   Telerik.Apoc.ApocDriver.Render(XmlReader inputReader, Stream outputStream) +334
   Telerik.Apoc.ApocDriver.Render(TextReader inputReader, Stream outputStream) +41
   Telerik.WebControls.Grid.Export.TableViewExporter.PdfExportRenderForm(HtmlTextWriter nullWriter, Control form) +1072
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +2065835
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +59
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +68
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +37
   Telerik.WebControls.Grid.Export.TableViewExporter.PdfExportRenderPage(HtmlTextWriter nullWriter, Control page) +102
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +2065835
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
   System.Web.UI.Page.Render(HtmlTextWriter writer) +26
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1896

Any feedback is appreciated

8 Answers, 1 is accepted

Sort by
0
Juan_Massyn
Top achievements
Rank 1
answered on 01 Sep 2008, 09:18 AM
Hi,

Any ideas on the mentioned error yet? If you require more information, let me know please.

Regards,
0
Vlad
Telerik team
answered on 01 Sep 2008, 10:59 AM
Hi Juan_Massyn,

This may happen if you try to export large recordset at once - can you verify if this is the case at your end?

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shane
Top achievements
Rank 1
answered on 21 Oct 2008, 06:38 AM
I'm getting the same issue. And yes it's a large recordset (around 5000 rows). Any ideas how to overcome this exception?
0
Pavel
Telerik team
answered on 23 Oct 2008, 12:47 PM
Hello Bardia,

Unfortunately there is little that can be done when trying to export large amounts of data. You should have in mind that when IgnorePaging is set to true, RadGrid instance will be bound to all of the 5000 records which is quite memory consuming. Exporting and storing such large amount of data in session variable will cause scalability problem. I can suggest you either to consider decreasing the amount of data or export only the current page by setting the IgnorePaging option to 'false'.


Sincerely yours,
Pavel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike Nogen
Top achievements
Rank 1
answered on 03 Feb 2009, 10:57 AM
"RadGrid instance will be bound to all of the 5000 records which is quite memory consuming"
Yes they way you have done it :-)

"Unfortunately there is little that can be done when trying to export large amounts of data"
Why not only bind to the current view and step to the next page and rebind and continue this until all the pages in the grid have been exported. Then you don´t have this issue.

Like this for example:
        ExcelFile excelFile = new ExcelFile();  
            MemoryStream Stream = new MemoryStream();  
            ExcelWorksheet ws = excelFile.Worksheets.Add("Worksheetname");  
 
            int CurrentPageIndexBeforeExport = RadGrid1.CurrentPageIndex;  
              
            int TotalPageCount = this.RadGrid1.PageCount;  
            int PageCounter = 0;  
            int ItemCounter = 1;  
            for (PageCounter = 0; PageCounter < TotalPageCount; PageCounter++)  
            {  
                RadGrid1.CurrentPageIndex = PageCounter;  
                this.RadGrid1.Rebind();  
                foreach (GridDataItem Item in RadGrid1.MasterTableView.Items)  
                {  
                    if (Item is GridDataItem)  
                    {  
                        //Export row to excel  
                        ws.Cells["A" + ItemCounter.ToString()].Value = Item["Catalogue"].Text;  
                        //ws.Cells["A" + ItemCounter.ToString()].Style.Font.Weight = ExcelFont.BoldWeight;  
                        ws.Cells["B" + ItemCounter.ToString()].Value = Item["CoverTitle"].Text;  
                        ws.Cells["C" + ItemCounter.ToString()].Value = Item["ReportPeriod"].Text;  
                        ws.Cells["D" + ItemCounter.ToString()].Value = Item["SalesPeriod"].Text;  
                        ws.Cells["E" + ItemCounter.ToString()].Value = Item["SalesCountry"].Text;  
                        ws.Cells["F" + ItemCounter.ToString()].Value = Item["ItemsSold"].Text;  
                        ItemCounter++;  
                    }  
                }  
            }  
            RadGrid1.CurrentPageIndex = CurrentPageIndexBeforeExport;  
 
             
 
            //Saving excel and pushing it out to user  
            excelFile.SaveXls(Stream);  
            Response.ContentType = "Application/vnd.ms-excel";  
            Response.AddHeader("Content-Disposition""attachment; filename=" + ExcelName);  
            byte[] arrByteExcel = Stream.GetBuffer();  
            Response.AddHeader("content-length", System.Convert.ToString(arrByteExcel.Length));  
            Response.BinaryWrite(arrByteExcel);  
            Response.End(); 
0
Pavel
Telerik team
answered on 04 Feb 2009, 08:13 AM
Hi Mike,

In order for your suggestion to work it is required to have Microsoft Office installed on the server. Since this is not the idea behind the export functionality (we cannot force our clients to install MS Office in order to simply make a feature work) your approach is not applicable for us. However if it works for you or anyone else, you are free to implement it.

Pavel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike Nogen
Top achievements
Rank 1
answered on 27 Apr 2009, 06:50 AM
"In order for your suggestion to work it is required to have Microsoft Office installed on the server."
No.

"we cannot force our clients to install MS Office in order to simply make a feature work"
Sure I´ll understand that.

But what I have done is used a 3-party component written in 100% managed C# code. It can be done for sure without Office etc. It´s just that you guy´s have choosen the wrong approach (smile)

http://www.gemboxsoftware.com/GBSpreadsheet.htm
0
dany7487
Top achievements
Rank 1
answered on 04 Dec 2009, 10:16 PM
Hello!!!

Let me share with you what solved my problem.

I got rid of the Grid and did a query to the DB with a sqldatareader, then loop it and send the text using the Response object and it worked!! This can be used if you don´t need the grid to display the data, only to export it to excel.

Please see this post:
http://www.codeproject.com/KB/database/ExportDataToExcelUsingCS.aspx

Hope this helps to export large data to Excel.

Regards,
Tags
Grid
Asked by
Juan_Massyn
Top achievements
Rank 1
Answers by
Juan_Massyn
Top achievements
Rank 1
Vlad
Telerik team
Shane
Top achievements
Rank 1
Pavel
Telerik team
Mike Nogen
Top achievements
Rank 1
dany7487
Top achievements
Rank 1
Share this question
or