zoukankan      html  css  js  c++  java
  • 在页面实现数据还原,在终止数据库进程时,报不能用kill来终结自己的进程

    这是终止进程的存储过程
    use master
    go
    ---------------------------------------
    --关闭指定数据库的全部访问进程
    ---------------------------------------------
    create proc killspid
    @dbname varchar(200) --要关闭进程的数据库名
    as
    declare @sql nvarchar(500)
    declare @spid nvarchar(20)
    declare #tb cursor for
    select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
    open #tb
    fetch next from #tb into @spid
    while @@fetch_status=0
    begin
    exec('kill '+@spid)
    fetch next from #tb into @spid
    end
    close #tb
    deallocate #tb
    go

    看你的脚本的意思是:
    在master数据库建存储过程:killspid,
    如果你的目的也是这样,那么执行执行还原的sql语句应该是这样:
    use masrer
    go
    exec killspid 'dbname'--dbname改成要还原的数据库名称
    go
    --在这里写RESTORE 语句还原你的数据库
    go

    如果你的意图不是上面的,而是在要还原的数据上面创建killspid存储过程,估计你将无完达到你的目的,因为你要执行killspid时,执行killspid的进程也在你要kill的进程列表里面,就出现了你所说的情况:不能用kill来终结自己的进程;

    建议直接用sql语句而不是存储过程:
    use master    --须使用use master
    go

    declare @dbname nvarchar(500)
    set @dbname ='dbname'  --dbname改成要还原的数据库名称
    declare @spid nvarchar(20)
    declare #tb cursor for
    select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
    open #tb
    fetch next from #tb into @spid
    while @@fetch_status=0
    begin
    exec('kill '+@spid)
    fetch next from #tb into @spid
    end
    close #tb
    deallocate #tb
    go

  • 相关阅读:
    密码保护
    实现搜索功能
    完成个人中心—导航标签
    个人中心标签页导航
    评论列表显示及排序,个人中心显示
    完成评论功能
    从首页问答标题到问答详情页
    首页列表显示全部问答,完成问答详情页布局
    Android基础学习:Android环境搭建
    liunx 硬盘分区
  • 原文地址:https://www.cnblogs.com/scgw/p/1925044.html
Copyright © 2011-2022 走看看