--当很多连接到你的数据库时,报这种错误“已超过了锁请求超时时段”
--直接把下在面的存储过程 放到你的Master数据库执行一下就可以了
1 USE pratice 2 SET ANSI_NULLS ON 3 SET QUOTED_IDENTIFIER ON 4 go 5 6 create PROC [dbo].[Sp_KillAllProcessInDB] @DbName VARCHAR(100) 7 AS 8 IF DB_ID(@DbName) = NULL 9 BEGIN 10 PRINT 'DataBase dose not Exist' 11 END 12 ELSE 13 BEGIN 14 DECLARE @killspId VARCHAR(30) 15 DECLARE TmpCursor CURSOR 16 FOR 17 SELECT 'Kill ' + CONVERT(VARCHAR, spid) AS spId 18 FROM master..SysProcesses 19 WHERE DB_NAME(dbid) = @DbName 20 AND spid <> @@spid --终止不是当前进程的进程(不等于当前进程) 21 AND dbid <> 0 --数据库ID不是0 22 OPEN TmpCursor 23 FETCH NEXT FROM TmpCursor 24 25 INTO @killspId --select into @killspId 26 WHILE @@FETCH_STATUS = 0 27 BEGIN 28 EXEC (@killspId) 29 FETCH NEXT FROM TmpCursor 30 INTO @killspId 31 32 END 33 34 CLOSE TmpCursor 35 DEALLOCATE TmpCursor 36 END 37 38 exec Sp_KillAllProcessInDB '要访问的数据库'
(以上转载来自:http://www.cnblogs.com/lyhabc/articles/3235601.html)
查看锁定的进程ID
SELECT blocking_session_id '阻塞进程的ID', wait_duration_ms '等待时间(毫秒)', session_id '(会话ID)' FROM sys.dm_os_waiting_tasks