0

Using ADO.NET Datareader an user extracts data from a database table having 1000 rows. He closed his browser in between.

That is after fetching only 50 records. What happens to the Datareader? Will it remain connected?

And will fetch 1000 records and what after? Will garbage collector collect and dispose it soon?

Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166
F11
  • 3,703
  • 12
  • 49
  • 83
  • depends on implementation, the `DataReader` is generally disposed as part of the server-side response. Preferred implementation is usually with [using](http://msdn.microsoft.com/en-us/library/yh598w02(v=vs.110).aspx) statements...see http://stackoverflow.com/questions/744051/sqldatareader-dispose – MikeM Feb 26 '13 at 01:16

1 Answers1

1

Although mdmullinax is correct that you should have everything wrapped in using statements to ensure connections are properly cleaned up, your question has nothing to do with how DataReader is implemented.

Generally speaking, the page will continue executing even if the browser has disconnected.

So, if the DataReader is midway in reading responses from the server it will continue to pull the rest of the records before the DataReader signals back that it's processing is complete.

Then the rest of the code for the page completes execution and the response is flushed to the browser. Of course, the browser is long gone by this point so those packets end up dropped.. unless something is checking the Response.IsClientConnected property. Bear in mind that the IsClientConnected property isn't full proof as there are numerous ways a browser on the other end might disappear without notifying the server.

For more information look here: Does asp.net lifecycle continue if I close the browser in the middle of processing?

Community
  • 1
  • 1
NotMe
  • 87,343
  • 27
  • 171
  • 245