惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 一味

[翻译]实例:在Android调用WCF服务 基于LRU淘汰的高性能缓存 不是架构的架构之五:业务层的实现与自动代理(补充) 不是架构的架构之四:业务层的实现与自动代理 不是架构的架构之三:系统基础(2)主键选择和并发 不是架构的架构之二:系统基础(1) 不是架构的架构之一:总体思路 一道算法题 技术先行or业务先行 用了一年的键盘,记录下键盘磨损的状况 一个业务系统设计构想(一) 安装VS2008/.Net3.5/.Net3.0/.Net2.0sp1失败的解决办法 常用存储过程4(K310。3版本获取物流新单据的编码) 常用存储过程3(获取编码的上级编码和短编码) 常用存储过程2(获取编码级次) 常用存储过程1(获取字符串中的第一个数值) SQL Server中Rollup关键字使用技巧 Math.Round函数四舍五入的问题 学习NHibernate的感悟和疑惑
SQL Server进程阻塞的检查和解决办法(转自好友Blog)
一味 · 2006-06-29 · via 博客园 - 一味

先声明,这篇文章是转自一个好友(文心残)的Blog。
我最近在项目中遇到了这样的问题,这篇文章给了一个比较好的解决方案。

create procedure sp_who_lock
as
begin
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int
create table #tmp_lock_who (
id 
int identity(1,1),
spid 
smallint,
bl 
smallint)
IF @@ERROR<>0 RETURN @@ERROR
insert into #tmp_lock_who(spid,bl) select 0 ,blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from sysprocesses where blocked>0
IF @@ERROR<>0 RETURN @@ERROR
-- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who
IF @@ERROR<>0 RETURN @@ERROR
if @intCountProperties=0
select '现在没有阻塞信息' as message
-- 循环开始
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where Id = @intCounter
begin
if @spid =0
select '引起数据库阻塞的是: '+ CAST(@bl AS VARCHAR(10)) + '进程号,其执行的SQL语法如下'
else
select '进程号SPID:'+ CAST(@spid AS VARCHAR(10))+ '' + '进程号SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其当前进程执行的SQL语法如下'
DBCC INPUTBUFFER (@bl )
end
-- 循环指针下移
set @intCounter = @intCounter + 1
end

drop table #tmp_lock_who
return 0
end
GO


--结束SQL阻塞的进程%%%%%%%%%%%%%%%%%%%%%%
create    procedure sp_Kill_lockProcess
as
begin
        
SET NOCOUNT ON
 
declare @spid int,@bl int,
 
@intTransactionCountOnEntry int,
 
@intRowcount int,
 
@intCountProperties int,
 
@intCounter int,
        
@sSql nvarchar (200)
 
 
create table #tmp_lock_who (
 id 
int identity(1,1),
 spid 
smallint,
 bl 
smallint)
 
 
IF @@ERROR<>0 RETURN @@ERROR
 
 
insert into #tmp_lock_who(spid,bl)
        
select 0 ,blocked
 
from
        (
select * from sysprocesses where blocked>0 ) a
 
where not exists
        (
         
select * from (select * from sysprocesses where blocked>0 ) b
  
where a.blocked=spid
        )
 
union select spid,blocked from sysprocesses where blocked>0
 
 
IF @@ERROR<>0 RETURN @@ERROR
 
 
-- 找到临时表的记录数
 select @intCountProperties = Count(*),@intCounter = 1
 
from #tmp_lock_who
 
 
IF @@ERROR<>0 RETURN @@ERROR
 
 
while @intCounter <= @intCountProperties
 
begin
         
-- 取第一条记录
  select @spid = spid,@bl = bl
  
from #tmp_lock_who where Id = @intCounter
  
begin
   
if @spid =0
   
begin
                          
set @sSql='kill ' + CAST(@bl AS VARCHAR(10))
                          
exec sp_executesql @sSql
   
end
  
end
  
  
-- 循环指针下移
  set @intCounter = @intCounter + 1
 
end
 
 
drop table #tmp_lock_who
        
SET NOCOUNT OFF
 
return 0
end

GO