在SQL Server 2008 R2中,您可以在调试死锁时使用以下命令查找所有打开的事务:
DBCC OPENTRAN
但是,该功能在Windows Azure SQL数据库中不可用;它改为抛出错误:
"DBCC command 'OPENTRAN' is not supported in this version of SQL Server."
sp_who2
存储过程也不存在。
在Azure版本的SQL Server中获取所有打开的事务的正确查询是什么?
答案 0 :(得分:10)
尝试使用DMV:
SELECT *
FROM sys.dm_tran_active_transactions
SELECT *
FROM sys.dm_tran_database_transactions
SELECT *
FROM sys.dm_tran_session_transactions
答案 1 :(得分:1)
试试这个脚本:解释所有需要的案例。
SELECT
tdt.transaction_id
,tst.session_id
,tdt.database_transaction_begin_time
,CASE tdt.database_transaction_type
WHEN 1 THEN 'Read/write transaction'
WHEN 2 THEN 'Read only transaction'
WHEN 3 THEN 'System transaction'
END transaction_type
,CASE tdt.database_transaction_state
WHEN 1 THEN 'Transaction not initialized'
WHEN 3 THEN 'Transaction has not generated by any log'
WHEN 4 THEN 'Transaction has generated by log'
WHEN 5 THEN 'Transaction Prepared'
WHEN 10 THEN 'Transaction Committed'
WHEN 11 THEN 'Transaction Rolled back'
WHEN 12 THEN 'Transaction committed and log generated'
END transaction_state
FROM sys.dm_tran_database_transactions tdt
INNER JOIN sys.dm_tran_session_transactions tst
ON tst.transaction_id = tdt.transaction_id