关闭SQL SERVER用户进程,防止因为用户正在使用数据库,导致数据库恢复或删除失败

来源:互联网 发布:幼儿园视频监控软件 编辑:程序博客网 时间:2024/04/29 16:50

    //关闭SQL SERVER用户进程,防止因为用户正在使用数据库,导致数据库恢复或删除失败 

   isql:='select spid from master..sysprocesses where dbid=db_id(''mobile'')';
    adoquery1.Close;
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add(isql);
    adoquery1.Open;
    While not adoquery1.Eof  do
    begin
        adoquery2.Close;
        adoquery2.SQL.Clear;
        adoquery2.SQL.Add('kill ' + trim(adoquery1.FieldByName('spid').AsString));
        adoquery2.ExecSQL;
        adoquery1.Next;
    end;
 

原创粉丝点击