Reputation: 115
I have large record like more then 1 000 000 and I want to fill this data into DataTable, but at time of filling DataTable it is throwing exception like System.OutOfMemoryException
. How I can solve this error?
Also I have 4 GB RAM and 64-bit operating system.
Upvotes: 2
Views: 5683
Reputation: 28272
If you -need- all that data in memory, and your app pool is x64, and you are using .NET 4.5, you can use the gcAllowVeryLargeObjects
directive... to do this for ASP.NET, you'd need to add your own aspnet.config
file for your app pool (see this link for more info) and set this configuration for startup:
<configuration>
<runtime>
<gcAllowVeryLargeObjects enabled="true" />
</runtime>
</configuration>
That said, handling such a large DataTable
in memory all at once is more likely not the way to go, specially for web applications (which will generally work for more than one user).
Having that much memory occupied (per user, probably), while you more likely only work on a small subset of that memory at any given time, is just a waste, and you should probably be looking at a different way of handling the problem, rather than bruteforcing .NET to allow for larger objects in memory.
Upvotes: 6