System.OutOfMemoryException

9 posts, 0 answers
  1. Juan_Massyn
    Juan_Massyn avatar
    18 posts
    Member since:
    Mar 2007

    Posted 29 Aug 2008 Link to this post

    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
  2. Juan_Massyn
    Juan_Massyn avatar
    18 posts
    Member since:
    Mar 2007

    Posted 01 Sep 2008 Link to this post

    Hi,

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

    Regards,
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Sep 2008 Link to this post

    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.
  5. Shane
    Shane avatar
    8 posts
    Member since:
    Aug 2004

    Posted 21 Oct 2008 Link to this post

    I'm getting the same issue. And yes it's a large recordset (around 5000 rows). Any ideas how to overcome this exception?
  6. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 23 Oct 2008 Link to this post

    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.
  7. Mike Nogen
    Mike Nogen avatar
    34 posts
    Member since:
    May 2006

    Posted 03 Feb 2009 Link to this post

    "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(); 
  8. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 04 Feb 2009 Link to this post

    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.
  9. Mike Nogen
    Mike Nogen avatar
    34 posts
    Member since:
    May 2006

    Posted 27 Apr 2009 Link to this post

    "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
  10. dany7487
    dany7487 avatar
    88 posts
    Member since:
    Jan 2008

    Posted 04 Dec 2009 Link to this post

    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,
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017