Binding large dataset to Data Grid causes System.OutOfMemoryException Exception RRS feed

  • Question

  • I return a large dataset from a SQL Server database and set it as the data source for a data grid.


    When i Bind the data grid the ASPNET worker processes memory usage rises quickly until it eats all the remaining memory on the server and gives me the System.OutOfMemoryException.


    I was wondering if anyone knows why the databind method uses so much memory?

    I was also interested if any one has had this problem before and how they went about solving it.


    Below are the ideas I am considering

    1. Do a select count(id) from table before performing the databind, if the count is to high display a message to the user and ask them to refine there search.

    2. Use disconnected ADO, i don’t know much about this and it may require some rework on the page.

    3. Perform paging with in the sql query.

    4. Turn viewstate off. - This may be just delaying the error until a future date when the amount of rows in the table has grown.


    Any suggestions, comments, opinions would be much appreciated.


    Thanks in advance.


    Monday, February 4, 2008 1:44 AM

All replies

  • If you return large set of data, it will require process to use lots of memory to generate HTML output for you, and, of cause, will cause memory allocation issues. I believe it is pretty bad design (especially in ASP.NET applications) to select large sets of data in one shot. Do you really need to do this? What do you actually need to do with that data on client side? If it is for display purposes, then I would suggest implementing paging functionality and retrieving ONLY one specific page of data that will be returned to the client.
    Monday, February 4, 2008 10:55 AM