zoukankan      html  css  js  c++  java
  • 还原数据库出现“因为数据库正在使用,所以无法获得对数据库的独占访问权”解决方法

    今天在还原数据库时,服务器,出现"因为数据库正在使用,所以无法获得对数据库的独占访问权",因为有人在访问数据库",搜索了很久,终于的的到了解决办法,希望对朋友们有用.

    1、首先定位到好要还原的 数据库

    2、运行如下语句:

    declare @dbname varchar(20)
    set @dbname='sms_server'     ---这是数据库名称

    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
  • 相关阅读:
    HDU 6034
    HDU 6047
    CodeForces 830B
    HDU 4972
    HDU 4408
    CodeForces 788B
    CodeForces 788A
    CodeForces 792C
    uva 1658 Admiral 最小费最大流
    hdu 5391 Zball in Tina Town 威尔逊定理
  • 原文地址:https://www.cnblogs.com/mingyongcheng/p/2470159.html
Copyright © 2011-2022 走看看