SqlDataReader / DbDataReader implementation question

Posted by Jose on Stack Overflow See other posts from Stack Overflow or by Jose
Published on 2010-03-25T13:04:59Z Indexed on 2010/03/25 13:13 UTC
Read the original article Hit count: 480

Filed under:
|
|

Does anyone know how DbDataReaders actually work. We can use SqlDataReader as an example.

When you do the following

cmd.CommandText = "SELECT * FROM Customers";

var rdr = cmd.ExecuteReader();

while(rdr.Read())
{
  //Do something
}

Does the data reader have all of the rows in memory, or does it just grab one, and then when Read is called, does it go to the db and grab the next one? It seems just bringing one into memory would be bad performance, but bringing all of them would make it take a while on the call to ExecuteReader.

I know I'm the consumer of the object and it doesn't really matter how they implement it, but I'm just curious, and I think that I would probably spend a couple hours in Reflector to get an idea of what it's doing, so thought I'd ask someone that might know.

I'm just curious if anyone has an idea.

© Stack Overflow or respective owner

Related posts about sqldatareader

Related posts about dbdatareader