Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SqlClient.DataReader locks records? (ADO.Net)

Status
Not open for further replies.

JFritzler

Programmer
Jul 19, 2001
18
US
Does anyone know if SqlClient.DataReader locks the rows that is it currently reading?

I have a recursive call that that tries to execute "update" commands on the current row but it times out. (These are simle commands like "update table set field = value where primatykeyfield = 2". Nothing fancy, - in fact they run fine in the query analyser, but not at runtime.) I can't close the reader because I have more rows to process (to "read"). I need to use the "update" sql to mark the current row as being processed so it won't be processed the next time this feature is executed.

My theory is that the ADO.Net Reader locks the "read" rows. Does this sound possible? If so, can the behavior be changed?
 
In your SELECT command give a try using
SELECT * FROM A WITH (NOLOCK)

Thanks
Srini
 
Normaly Datareader get an exclusive access of the rows while datareader is executing. Datareader have to be used in cases where you should read some rows quickly, fill some controls like combobox and close the reader. Your case is a clasical example where you must use dataset to keep the rows so you can update one by one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top