user1526912
user1526912

Reputation: 17210

How to prevent System.OutOfMemoryException when retrieving large amounts of data in c#

I have a C# program that populates a dictionary with 4Million Guids at startup. I keep getting an Exception of type 'System.OutOfMemoryException' error at this point.

Example:

using (reportingconn)
{
    var initialrowkeys = reportingconn.Query("select rowkey from table”);
}

Can anyone give me some ideas how best to retrieve large amounts data from SQL into a dictionary?

Upvotes: 1

Views: 1412

Answers (2)

user1526912
user1526912

Reputation: 17210

It seems like there is a 2GB memory limitation on C# data dictionary. A programmer friend told me to change my console application from 32 bit to 64 bit to prevent that limitaion. That seems to have resolved my problem.

Upvotes: 0

iefpw
iefpw

Reputation: 7042

Use SqlDataReader() this will read row by row, instead of SqlDataAdapter.Fill.

Upvotes: 5

Related Questions