there's a problem that I'm seeking your help with...
There are two simple queries:
DELETE
a row from a table in a databaseASELECT
a row from a table in a databaseB using hintswith (updlock, rowlock)
Query 1 blocks query 2
The Blocked Process Report shows the following:
<blocked-process-report monitorLoop="914797">
<blocked-process>
<process id="process2e077f95088" taskpriority="0" logused="0" waitresource="KEY: 51:72057594213498880 (8bb5457f059a)" waittime="28217" ownerId="8906221681" transactionguid="0xeaa174df0998654799709e48bef6ff3b" transactionname="DTCXact" lasttranstarted="2021-12-13T17:28:22.620" XDES="0x2d960cd4040" lockMode="U" schedulerid="1" kpid="8748" status="suspended" spid="290" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2021-12-13T17:28:22.623" lastbatchcompleted="2021-12-13T17:28:22.623" lastattention="1900-01-01T00:00:00.623" clientapp=".Net SqlClient Data Provider" hostname="AAAAAA" hostpid="13524" loginname="XXX\User1" isolationlevel="read committed (2)" xactid="8906221681" currentdb="51" currentdbname="DatabaseB" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack>
<frame line="1" stmtstart="44" stmtend="884" sqlhandle="0x0200000092d95e215a495660d80f9ae81a21bb7563b968e60000000000000000000000000000000000000000" />
<frame line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" />
</executionStack>
<inputbuf>
SELECT stuff from whatever1.table1 WHERE bunch_of_things with (updlock, rowlock) </inputbuf>
</process>
</blocked-process>
<blocking-process>
<process status="sleeping" spid="58" sbid="0" ecid="0" priority="0" trancount="1" lastbatchstarted="2021-12-13T17:28:50.140" lastbatchcompleted="2021-12-13T17:28:50.140" lastattention="1900-01-01T00:00:00.140" clientapp=".Net SqlClient Data Provider" hostname="AAAAAA" hostpid="13524" loginname="XXX\User1" isolationlevel="read committed (2)" xactid="8906151325" currentdb="35" currentdbname="DatabaseA" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
<executionStack />
<inputbuf>
DELETE from whatever2.table2 WHERE bunch_of_things </inputbuf>
</process>
</blocking-process>
</blocked-process-report>
Looks like the blocked query is a distributed transaction (DTCXact), right? A query to sys.dm_tran_database_transactions shows that:
- the blocked query (the SELECT) is associated with just databaseB
- the blocking query (the DELETE) is associated with 3 databases: databaseA, databaseB and databaseC - wouldn't that mean a distributed transaction as well?
The queries come from NHibernate.
Would you please help me find the root cause of this blocking and how to solve it? Can it be related to misconfiguration in NHibernate? Connection pooling issue?
I'm out of ideas and I don't know much about NHibernate. I'm thinking of dropping the updlock
hint and maybe turning on Snapshot Isolation, but if it's the NHibernate's fault, then I'd rather have that corrected.
Thanks in advance...
whatever1.table1
andwhatever2.table2
, e.g. triggers? A distributed transaction is one that occurs across multiple servers (not just databases) typically.sp_reset_connection
sequence, while some don't. Those queries involved in the blocking don't. Can it mean connection reuse problems?