--断开指定库的所有用户连接(在master数据库中进行)use master
goif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_killspid]
GOcreate proc p_killspid
@dbname sysname  --要断开连接的数据库名
as  
declare @s nvarchar(1000)
declare tb cursor local for
select s='kill '+cast(spid as varchar)
from master..sysprocesses 
where dbid=db_id(@dbname)open tb 
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
go--调用
exec p_killspid  'aa'

解决方案 »

  1.   

    查询分析器: sp_who 查看哪些用户连接数据库然后: KILL <SPID> 断开相关用户
      

  2.   

    张老师,我说在网上有一个实现的方法.就是这个方法.也是邹建写的.比这还详细.
     叫做:VB实现SQL Server数据库备份/恢复 直接在vb中实现.就是感觉有点乱.
     在中国论坛网.
      

  3.   

    执行SQL:
    p_killspid [数据库名]