Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8351571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:40:29+00:00 2026-06-09T08:40:29+00:00

The work I do involves downloading into memory HUGE amounts of data from a

  • 0

The work I do involves downloading into memory HUGE amounts of data from a SQL server database. To accomplish this, we have custom dataset definitions that we load using a SqlDataReader, then iterate through the Datatable and build each row into an object, and then usually package those objects into a massive dictionary.

The amount of data we are using is large enough that sometimes it cannot fit into a single datatable which have a memory cap. The dictionaries have even grown large enough to surpass 8 gb’s of system memory in the most extreme cases. I was giving the task of fixing the outofmemory exceptions being thrown when the datatables overflowed. I did this by implementing a batch process method that seemed to be in conflict with how datatables are meant to be used, but it worked for the time being.

I now have the task of further reducing the memory requirements of this process. My idea is to create a generically typed class inheriting from IEnumerator that takes a SqlDataReader and essentially uses the reader as the collection it is Enumerating. The MoveNext() function will advance the reader, and the Current property will return the typed object specified built from a builder method from the reader’s current row.

My question: Is this a feasible idea? I’ve never heard/can’t find online anything like it.

Also, logistically: How would I call the specific builder function that the type declaration demands when the Current property is called?

I’m open to criticism and chastising for dreaming up a silly idea. I’m most interested in finding the best practice for approaching the overall goal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:40:30+00:00Added an answer on June 9, 2026 at 8:40 am

    Seems reasonably sensible, and actually pretty straightforward using an iterator block:

    private static IEnumerable<Foo> WrapReader(SqlDataReader reader)
    {
        while (reader.Read())
        {
            Foo foo = ...; // TODO: Build a Foo from the reader
            yield return foo;
        }
    }
    

    Then you can use it with:

    using (SqlDataReader reader = ...)
    {
        foreach (Foo foo in WrapReader(reader))
        {
            ...
        }
    }
    

    You can even use LINQ to Objects if you’re careful:

    using (SqlDataReader reader = ...)
    {
        var query = from foo in WrapReader(reader)
                    where foo.Price > 100
                    select foo.Name;
        // Use the query...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a task at work that involves converting legacy SGM files into XML.
I'm doing some work that involves inserting a batch of records into a Sql
Part of a new product I have been assigned to work on involves server-side
Work on C# Desktop project,I have an account on paypal ,From my desktop application
work on SQL Server 2000. want to Automated Email Notifications using SQL Server Job
This involves two automated unit tests which each start up a tcp/ip server that
Background I've picked up some incomplete work from another developer that involves displaying the
In this question,I'm asking how the following snippets work, as it involves weird use
This question involves Delphi and XE specifically deprecating Suspend and Resume. I have read
I'm doing some work for a client that involves parsing the referrer information from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.