【问题标题】:How do you find open transactions on Windows Azure SQL Database?如何在 Windows Azure SQL 数据库上找到未结事务?
【发布时间】:2014-05-01 08:40:34
【问题描述】:

在 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 中获取所有打开的事务的正确查询是什么?

【问题讨论】:

    标签: sql-server azure azure-sql-database


    【解决方案1】:

    尝试改用 DMV:

    SELECT *
    FROM sys.dm_tran_active_transactions
    
    SELECT *
    FROM sys.dm_tran_database_transactions
    
    SELECT *
    FROM sys.dm_tran_session_transactions
    

    【讨论】:

      【解决方案2】:

      试试这个脚本:解释所有需要的情况。

      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
      

      【讨论】:

        【解决方案3】:

        SQL DB v12 支持 dbcc opentran。请升级您的服务器。另一个选项是 sys.dm_tran_active_transactions

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-06-29
          • 1970-01-01
          • 1970-01-01
          • 2012-11-08
          • 2014-01-20
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多