0

I am using LINQ to select bulk data(156000 Records) from DB. But am getting the following error.

An exception of type 'System.OutOfMemoryException' occurred in System.Data.Entity.dll but was not handled in user code

Am using select query as follows,

var allCompanies = from s in db.Data.AsNoTracking().ToList()
                           select s;

Please help me to resolve this issue

5
  • By ToList(), you are trying to materialize the whole table in memory. Try selecting just the fields you need, or better still, filter the data before materializing it. Commented Mar 12, 2014 at 4:48
  • Hi stuart, thanks for your response. But if i removed .ToList() then also am getting same error Commented Mar 12, 2014 at 4:50
  • As an aside, AsNoTracking() will load deep copies of duplicate rows, not sure if this is relevant to your query? Commented Mar 12, 2014 at 4:55
  • Why would you need all those records at once? You can use pagination or process it on the server. Commented Mar 12, 2014 at 7:25
  • @StuartLC : thanks a lot, i retrived only selected fields. Its working for me Commented Mar 14, 2014 at 5:39

1 Answer 1

2

That is a large amount of records being retrieved. You may need more memory. Have you checked the amount of memory available on your System while this program is executing?

You may want to filter the data or make use of pagination by retrieving certain fixed rows of data at a time.

If it is viable, if you are considering processing the data after retrieving it, you might as well do that in a Stored Procedure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.