1

I am exporting large set of records from database to Dataset which may be a cause for System.OutofMemory exception. To prevent this, as first step I have decided to use SQL Datareader. My concern is presentation should not be changed and there should be minimal code change in BL, I should write a method in DL which should retrieve data using SQL reader and fill the dataset and return to BL.

6
  • have you thought about using SqlDataAdapter.Fill(DataTable)? Commented Sep 23, 2011 at 7:52
  • Currently I am using DataAdapter only to fill records to dataset! Commented Sep 23, 2011 at 7:56
  • I see, are you trying to get all the data from the table or only records matching a specific criteria? Commented Sep 23, 2011 at 7:58
  • Only records matching a specified search criteria Commented Sep 23, 2011 at 7:58
  • about how many records are returned then? Commented Sep 23, 2011 at 8:00

2 Answers 2

3

You can use DataTable.Load() method.

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

2 Comments

I am trying to get data using DataReader instead of DataAdapter, because I need to handle large amount of data. After getting using ExecuteReader(), i am loading it to datatable. So whether this is a good approach. ?
@Harie - I suggest the Load() method. Fill() especially used to populates DataSet (adding one or more tables), creates relations and so on. Have a look at article by Scott Mitchell- 4guysfromrolla.com/articles/050405-1.aspx
2

Whether you or the Framework fills the DataSet you'll have the OutOfMemoryException. You have to return an IEnumerable and change the BL code to handle it.

Alternatively, you could try to set the DataTable.MinimumCapacity to avoid memory fragmentation.

1 Comment

+1 because I agree - how does going via a datareader help reduce memory usage? Presumably though it may be possible to do crazy things with an object that looks like a DataTable but actually has an ienumerabe inside it to return row data. Would be tricky to do but could prevent problems with recoding the BL.

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.