Question

It appears that under the covers SqlDataReader will actuall grab multiple rows at a time

I have a situation where I need to to grab a single row at a time. In the SqlDataReader loop I may change, insert, or delete rows using a separate SQLcommand. The problem I have is that may be a change to data the SqlDataReader has prefetched so I get stale data. I don't really need to see the inserts performed in the loop but if I read them it does not break anything.

How do I get SqlDataReader.Read() to actually read a single row at a time from the database?

Was it helpful?

Solution

SQL Server puts as many result set rows as possible in network packets and sends them to the client as fast as possible. The packets containing the result set rows are then cached in the network buffers of the client and read by the accessing driver.
It would be very slow to read them one by one and send them to the client.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top