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
  • 相关阅读:
    Mysql知识:事务
    Mysql知识 索引补充
    Mysql知识:索引
    Leetcode 78 子集
    每日总结
    个人冲刺-第二阶段(8)
    每日总结
    个人冲刺-第二阶段(7)
    每日总结
    个人冲刺-第二阶段(6)
  • 原文地址:https://www.cnblogs.com/mingyongcheng/p/2470159.html
Copyright © 2011-2022 走看看