sqlserver 2000 如何查询未提交的事务

山城忙碌人 2011-05-05 04:58:57
如题:
环境:java+sqlserver2000
问题描述:tomcat启动后,程序运行过程中出现事务提交不了(注:功能比较少,不是一用某个功能就出现事务提交不了),要过很久有时才能正常,有时必须重启动服务器程序。
提问:sqlserver 2000 如何查询未提交的事务,通过企业管理器可以查询吗。如果不能的话,我怎么找到是哪个进程ID(通过企业管理器看阻塞ID)造成了事务未提交,我能不能结束该进程ID,让该进程ID的事务回滚,如何在不重启动tomcat的情况下,结束事务,可以让未结束的事务回滚。
...全文
322 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
GameWong 2011-05-05
  • 打赏
  • 举报
回复
是spid,不是objid
山城忙碌人 2011-05-05
  • 打赏
  • 举报
回复
谢谢。我试试。
GameWong 2011-05-05
  • 打赏
  • 举报
回复
--事务的起始和提交。
begin tran
commit tran


sp_lock查询锁
——查询出锁的进程ID,记得好像是objID

kill XX 杀出锁
——(xx为要杀除的锁的id,既是objID)
bill024 2011-05-05
  • 打赏
  • 举报
回复

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

找到后KILL掉进程ID

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧