DataReader Behaviour With SQL Server Locking

Posted by Graham on Stack Overflow See other posts from Stack Overflow or by Graham
Published on 2009-10-08T15:48:53Z Indexed on 2010/06/14 11:42 UTC
Read the original article Hit count: 294

Filed under:
|
|

We are having some issues with our data layer when large datasets are returned from a SQL server query via a DataReader. As we use the DataReader to populate business objects and serialize them back to the client, the fetch can take several minutes (we are showing progress to the user :-)), but we've found that there's some pretty hard-core locking going on on the affected tables which is causing other updates to be blocked.

So I guess my slightly naive question is, at what point are the locks which are taken out as a result of executing the query actually relinquished? We seem to be finding that the locks are remaining until the last row of the DataReader has been processed and the DataReader is actually closed - does that seem correct? A quick 101 on how the DataReader works behind the scenes would be great as I've struggled to find any decent information on it.

I should say that I realise the locking issues are the main concern but I'm just concerned with the behaviour of the DataReader here.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about lock