我的开发工具前台是PB9,后台是 SQL Server 2000,当多用户同时登录同一窗口并对其操作时,只允许一个用户对其操作,而其它用户都必须进入等待状态,这时就会发生了窗口的假死现象,请问各位高手如何解决这一问题.如果有更好的解决方法,分不成问题.请发到我的邮箱 wangyong@bigtide.com
...全文
16813打赏收藏
在SQL Server 中如何解决多用户发生的锁定问题.在线等侯.急急急
我的开发工具前台是PB9,后台是 SQL Server 2000,当多用户同时登录同一窗口并对其操作时,只允许一个用户对其操作,而其它用户都必须进入等待状态,这时就会发生了窗口的假死现象,请问各位高手如何解决这一问题.如果有更好的解决方法,分不成问题.请发到我的邮箱 wangyong@bigtide.com
在事务结束后它自己会解琐,如果发生死锁需要用kill杀掉。如:
use master
go
create proc killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500),@temp varchar(1000)
declare @spid int
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status<>-1
begin
set @temp='kill '+rtrim(@spid)
exec(@temp)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end
http://expert.csdn.net/Expert/topic/2218/2218218.xml?temp=.099621
/********** 加锁 ***************
设table1(A,B,C)
A B C
a1 b1 c1
a2 b2 c2
a3 b3 c3
1)排它锁
新建两个连接
在第一个连接中执行以下语句
begin tran
update table1
set A='aa'
where B='b2'
waitfor delay '00:00:30' --等待30秒
commit tran
在第二个连接中执行以下语句
begin tran
select * from table1
where B='b2'
commit tran
若同时执行上述两个语句,则select查询必须等待update执行完毕才能执行即要等待30秒
2)共享锁
在第一个连接中执行以下语句
begin tran
select * from table1 holdlock -holdlock人为加锁
where B='b2'
waitfor delay '00:00:30' --等待30秒
commit tran
在第二个连接中执行以下语句
begin tran
select A,C from table1
where B='b2'
update table1
set A='aa'
where B='b2'
commit tran
3)死锁
增设table2(D,E)
D E
d1 e1
d2 e2
在第一个连接中执行以下语句
begin tran
update table1
set A='aa'
where B='b2'
waitfor delay '00:00:30'
update table2
set D='d5'
where E='e1'
commit tran
在第二个连接中执行以下语句
begin tran
update table2
set D='d5'
where E='e1'
waitfor delay '00:00:10'
update table1
set A='aa'
where B='b2'
commit tran
同时执行,系统会检测出死锁,并中止进程
--------------------------------------------------------------
SET IMPLICIT_TRANSACTIONS ON --用户每次必须显式提交或回滚。否则当用户断开连接时,
--事务及其所包含的所有数据更改将回滚
SET IMPLICIT_TRANSACTIONS OFF --自动提交模式。在自动提交模式下,如果各个语句成功
--完成则提交。