SQL SERVER错误:已超过了锁请求超时时段。

时间:2022-02-05 00:38:57

问题:远程连接数据库,无法打开视图,报错:SQL SERVER错误:已超过了锁请求超时时段。 (Microsoft SQL Server,错误: 1222)

执行语句获取进程id

select * from master..sysprocesses where DB_NAME(dbid)='your db'
and spid<>@@SPIDand dbid<>0and open_tran>0

 

切换master 
 
kill spid
 
批量清理方法
 
DECLARE @sql NVARCHAR(MAX),@currDbName NVARCHAR(100)
SET @currDbName='your db'    --如果在当前库上执行,可改为: SET @currDbName = DB_NAME()
WHILE EXISTS( SELECT 1 FROM sys.sysprocesses WHERE dbid=DB_ID(@currDbName) AND spid!=@@SPID )
BEGIN
SELECT TOP 1 @sql='kill '+CAST(spid AS NVARCHAR(50)) FROM sys.sysprocesses WHERE dbid=DB_ID(@currDbName) AND spid!=@@SPID 
EXEC (@sql)    
END