我作了一个与数据库相关的小软件,备份没问题,就是恢复时说正在使用,一般来说数据备份和恢复不是备份和恢复整个数据库吗?
   我的代码:就是没有进度的,我也没知道怎么加进去,谁帮下,谢谢
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;type
  TForm1 = class(TForm)
    Button1: TButton;
    dlgOpen1: TOpenDialog;
    con1: TADOConnection;
    qry1: TADOQuery;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
    if   dlgOpen1.Execute   then
            begin 
                try 
                con1.Connected:=False;
                con1.Connected:=True;
                with   qry1   do
                    begin 
                        Close; 
                        SQL.Clear; 
                        SQL.Add('Backup   DataBase  test   to   disk   = '''+dlgopen1.FileName+ '''');
                        ExecSQL; 
                    end; 
                except 
                          ShowMessage( '备份失败 '); 
                          Exit; 
                end; 
            end; 
    Application.MessageBox( '备份成功 ', '备份信息 ',MB_OK   +   MB_ICONINFORMATION);
end;procedure TForm1.Button2Click(Sender: TObject);
begin  if  dlgOpen1.Execute   then
    begin
      try
        con1.Connected:=false;
        con1.Connected:=true;
        with   qry1   do
        begin
          Close;
          SQL.Clear;
          SQL.Add( 'Restore   DataBase   test   from   disk   = '''+dlgopen1.FileName+ '''');
          ExecSQL;
        end;
      except
         ShowMessage( '恢复数据失败 ');
         Exit;
      end;
    end;
          Application.MessageBox( '恢复数据成功 ', '恢复信息 ',MB_OK   +   MB_ICONINFORMATION); 
end;end.

解决方案 »

  1.   

    加进度条方法
    把ADOQuery的ExcuteOption属性设为 eoAsyncFetch, 再在FetchProgress 中写代码 procedure TForm1.ADODataSet1FetchProgress(DataSet: TCustomADODataSet; Progress, MaxProgress: Integer; var EventStatus: TEventStatus); 
    begin 
      Caption :=  'Percent complete:  ' + 
        IntToStr(Trunc(Progress / MaxProgress * 100)) +  '% '; 
      Application.ProcessMessages; 
    end; 
      

  2.   

    备份和恢复数据库不建议你那样做,我一般是只备份经常使用的某个表,新建一个表,把数据拷过去就行了,恢复也方便,把数据从备份表中复制过来,另外 你也可以采取备份文件的方式:copyfile
      

  3.   

    应该是文件没有关联好的问题>>>>