因为数据库有人在使用,要kill该数据库的所有进程后再detach数据库才行。

解决方案 »

  1.   

    停止SQL服务,再启动,再作你要作的
      

  2.   

    查找出使用该数据库的进程,然后杀死进程
    首先使用USE MASTER  使自己不再访问所要DETACH的数据库
    使用
    select identity(int,1,1) as ID,spid into @userprocess from master..sysprocesses
    where db_id=db_id('你的数据库的名字')
    declare @cunt int
    declare @maxcount int
    declare @spid varchar
    set @count=1
    select @maxcount=count(*) from @userprocess
    while @cunt<=@maxcount
    begin
    select @spid=spid from @userprocess where id=@cunt
    exec('kill '+@spid)
    end
      

  3.   

    修正
    上面建立临时表改用#userprocess而不是@userprocessselect identity(int,1,1) as ID,spid into #userprocess from master..sysprocesses
    where db_id=db_id('你的数据库的名字')
    declare @cunt int
    declare @maxcount int
    declare @spid varchar
    set @count=1
    select @maxcount=count(*) from #userprocess
    while @cunt<=@maxcount
    begin
    select @spid=spid from @userprocess where id=@cunt
    exec('kill '+@spid)
    end