4 May 2012

SQL SERVER – Alternate Fix : ERROR 1222 : Lock request time out period exceeded


Here is the script that can kill locks
Create Table #Tmp
(
spid smallint,
ecid smallint,
status nchar(30),
loginame nchar(128),
hostname nchar(128),
blk char(5),
dbname nchar(128),
cmd nchar(16)
)
Create Table #TmpLocks
(
spid smallint,
dbid smallint,
ObjId int,
IndId smallint,
Type nchar(4),
Resource nchar(16),
Mode nvarchar(8),
Status nvarchar(28)
)
Insert Into #Tmp
Exec sp_who
Insert Into #TmpLocks
Exec sp_lock
If(Select Count(*) From #Tmp T
Join #TmpLocks TL On T.spid = TL.spid
Where /*This is for tempdb*/ dbid = 2 And objid In (1, 2, 3)) > 0
Then you can kill the concerned spid with the command :
Kill — The concerned spid
Drop Table #Tmp
Drop Table #TmpLocks

No comments:

Post a Comment