Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

system.outofmemoryexception When filling DataAdapter?

I have to pull 150K records from DB. I am using da.Fill(ds,"Query") and its throwing system.outofmemoryexception.

Dim daGrid As New SqlDataAdapter(sqlcmd_q)
daGrid.Fill(dsGrid, "Query")
daGrid.Dispose()

I need this datatable only. I cannot use XML. because I need assign this to MSChartControl to display ScotterPlot.

Any suggestions?

like image 366
James123 Avatar asked Feb 23 '11 14:02

James123


People also ask

How do you fix system OutOfMemoryException exception of type system OutOfMemoryException was thrown?

OutOfMemoryException Exception of type 'System. OutOfMemoryException' was thrown. To resolve this issue, I had to restart Visual Studio or go to the Windows Task Manager and terminate IIS Express process. This error could happen due to a variety of reasons related to memory consumption of the application.

What is System OutOfMemoryException?

When data structures or data sets that reside in memory become so large that the common language runtime is unable to allocate enough contiguous memory for them, an OutOfMemoryException exception results.

What does Sqldataadapter fill do?

The Fill method of the DataAdapter is used to populate a DataSet with the results of the SelectCommand of the DataAdapter . Fill takes as its arguments a DataSet to be populated, and a DataTable object, or the name of the DataTable to be filled with the rows returned from the SelectCommand .


1 Answers

The first thing that I'd check is how many columns you are returning, and what their data types are. Although 150K records is a lot, it shouldn't give you an OOM exception unless each record is about 13K in length (on a 32-bit machine). This suggests to me that you are either returning way more fields than you need, or perhaps that some of the fields are very large strings or binary data. Try cutting down the select statement to only return the fields that are absolutely needed for the display.

If that doesn't work, you may need to move from a DataTable to a list of a custom data type (a class with the appropriate fields).

like image 86
Chris Shain Avatar answered Sep 28 '22 22:09

Chris Shain