假如我在ssm里面就不进行提交事务
c#执行代码时出现错误:
内容
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.\r\nOperation cancelled by user.\r\nThe statement has been terminated
怎么定位呢
使用如下查看sessionid
FROM sys.dm_exec_requests
CROSS APPLY sys.dm_exec_sql_text(sql_handle);
![](https://img.haomeiwen.com/i2815884/cd69c841f373f18a.png)
但是这个是没用的
![](https://img.haomeiwen.com/i2815884/d1b56aa32bef6d2e.png)
sELECT
request_session_id AS SessionID,
resource_type AS ResourceType,
resource_database_id AS DatabaseID,
resource_associated_entity_id AS AssociatedEntityID,
request_mode AS LockMode,
request_status AS LockStatus
FROM sys.dm_tran_locks
WHERE resource_type = 'OBJECT' OR resource_type = 'PAGE';
强行杀死
![](https://img.haomeiwen.com/i2815884/aab0e483770fbf32.png)
告知了原因。
其他命令
DBCC TRACEON (1222, -1); -- 1222 追踪标记会输出更详细的死锁信息
DBCC TRACEOFF (1222, -1);
SELECT * FROM sys.dm_tran_locks
SELECT * FROM sys.dm_exec_requests
SELECT cntr_value AS NumOfDeadLocks ,*
FROM sys.dm_os_performance_counters
WHERE object_name LIKE '%Locks%'
最后还是这个语句吧
select
request_session_id spid,request_owner_type,
OBJECT_NAME(resource_associated_entity_id) tableName,*
from
sys.dm_tran_locks
where
resource_type='OBJECT'
![](https://img.haomeiwen.com/i2815884/5a0d8b3e7ff1f90c.png)
所以对于这种事务锁直接
COMMIT TRAN
不需要写事务名
网友评论