oupatch
在还原数据库时,有时会提示因为数据库正在使用,所以无法获得对数据库的独占访问权!!
这时需要在还原数据库前先杀死正在使用数据库得线程.

如以下杀死正在使用\'Calendar3\'数据库的线程:

declare @dbname varchar(20)
set @dbname=\'Calendar3\'

declare @sql nvarchar(500)
declare @spid int--SPID 值是当用户进行连接时指派给该连接的一个唯一的整数
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--如果FETCH 语句没有执行失败或此行不在结果集中。
begin
exec(\'kill \'+@spid)--终止正常连接
fetch next from getspid into @spid
end
close getspid
deallocate getspid

分类:

技术点:

相关文章:

  • 2022-01-30
  • 2021-12-19
  • 2021-11-18
  • 2021-12-05
  • 2021-12-12
  • 2022-01-30
猜你喜欢
  • 2021-12-11
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案