In a SQL Server database, I have two tables, s and t. A further link table joins the two. THe relationship is one s to many t.
I have the following issue (In order of operation:)
- An update stored procedure starts on table t.
- A select by id stored procedure starts that selects from a view on table t and a view on table s.
The rows updated in table t are NOT linked to the Ids in table s that (2) is querying.
Both SPs take longer than expected to finish, implying some resource contention. (2) finishes before (1) completes, but only seems to return data from with view on s, not t. Finally, (1) finishes successfully. No deadlocks are reported – I have handling in place for these based upon SQL exception number.
Any thoughts? I think maybe the lock acquired by (1) stops (2) accessing the view on t, yet (2) finishes before (1)!
Thanks all for your responses.
As it turns out a deadlock WAS occurring! However the stored proc returns 2 views, of which only the 2nd deadlocks. The
SqlCommandreturns these views into aSqlDataReader, which is read using a generic method with a passed in datareader method delegate.Unfortunately, a bug in the
SqlDataReaderclass (see http://support.microsoft.com/kb/316667) stopped the deadlock exception from propagating and therefore the operation was not retried.I’ve worked around this by using a
DataAdapterclass to fill aDataSet, instead of theSqlDataReader. The deadlock excpetion is now thrown and can be retried successfully.