提示:
sp_who
sp_who2
kill

解决方案 »

  1.   

    用一下sqlserver提供的对象
    我有vb的恢复例子
    [email protected]
      

  2.   

    use master
    Go
    restore
    因为你不能在连接该数据库的情况下恢复该数据库此外近来我发现一个很好的方法,在服务器上运行:
    osql -S (local) -U sa -P -o "results.txt" -i "installDB.txt" 
    以下installDB.txt
    Exec sp_detach_db 'ebookstore','true'
    Exec sp_attach_single_file_db @dbname='ebookstore',@physname='F:\ASPXML\DB\ebookstore.mdf'
    其中osql是sqlserver自带的一个小程序,好,真得很方便
      

  3.   

    上面的也可以在查询分析器中运行!不过我的程序运行的时候数据库停不下来,
    use master
    不行啊!急!~~~~~~~~~~~·
      

  4.   

    备份:begin
        pgbar.Max:=100;
        pgbar.Min:=0;
        pgbar.Step:=20;
         adoconnection1.Close;
         if adoconnection1.Connected then
         begin
            application.MessageBox('数据库数据正在使用','系统提示')
         end
         else
              begin
              try
                adocommand1.CommandText:='use master';
                pgbar.StepIt;
                adocommand1.Execute ;
                adocommand1.CommandText:='execute sp_helpdevice';
                pgbar.StepIt;
                adocommand1.Execute ;
                pgbar.stepit;
                adocommand1.CommandText:='backup database docmanage to disk=''c:\ccc.bak'' with init';
                pgbar.StepIt;
                adocommand1.Execute ;
                adocommand1.CommandText:='backup log docmanage to ccc';
                pgbar.StepIt;
                adocommand1.Execute;
                try
                   aDOConnection1.Connected:=true;
                except
                  ShowMessage('无法连接指定的数据库!');
                  application.Terminate;
                end;
                form1.Hide;
                  if messagedlg('数据库docmanage已成功备份到c:\ccc.bak!是否继续?',mtwarning,[mbok],0)=mrok then
                     begin
                       form1.close
                     end;
              except
                 on exception do
                     if ADOConnection1.InTransaction then
                         ADOConnection1.RollbackTrans
    end;
    end;
    end;
    还原:
    begin
      adoconnection1.Close ;
     if adoconnection1.Connected then
         begin
            application.MessageBox('数据库数据正在使用!','系统提示')
         end
         else
              begin
                pgbar.Max:=100;
                pgbar.Min:=0;
                pgbar.Step:=20;
                try
                    ADOCommand1.CommandText:='use master ';
                    pgbar.StepIt;
                     pgbar.StepIt;
                    adocommand1.Execute ;
                    adocommand1.CommandText:='RESTORE database docmanage FROM DISK = ''c:\ccc.bak''  with replace ';
                    pgbar.StepIt;                pgbar.StepIt;
                    pgbar.StepIt;
                    adocommand1.Execute ;
                     try
                         aDOConnection1.Connected:=true;
                     except
                        ShowMessage('无法连接指定的数据库!');
                        application.Terminate;
                     end;
                    form1.Hide;
                      if messagedlg('c:\ccc.bak已成功还原到数据库docmanage!继续?',mtwarning,[mbok],0)=mrok then
                         begin
                           form2.close
                      end;
                except
                   on exception do
                       if ADOConnection1.InTransaction then
                          ADOConnection1.RollbackTrans;
                end;
    end;
    end;
      

  5.   

    不过我的程序运行的时候数据库停不下来,
    use master
    不行啊!急!~~~~~~~~~~~·
    -------------
    use master
    并不是让你的数据库停下来,
    意思是让你选连MASTER库,再进行RESTORE
      

  6.   

    你在程序中写的话,如果使用TDatabase,将之连接到master数据库,然后再程序中的TQuery使用之,即可。