在delphi中用TIBBackupService控件对数据库进行备份,但是如果备份失败,关闭控件后,数据库文件无法释放,请问会是什么原因?

解决方案 »

  1.   

    肯定是進程還在運行中如果只是想利用delphi對數據庫進行備份和還原的操作,可以用代碼實現:(參考之)1.備份;procedure Tsys_datamodule.DataBaseBack;
    var
      FileName:string;
      ADOQ:TADOQuery;
    begin
      ADOQ:=TADOQuery.Create(nil);
      ADOQ.Connection:=sys_datamodule.con1;
      if MessageDlg('你確定要備份數據庫嗎?',mtInformation,[mbYes,mbNo],0)=idyes then
      begin
        try
          if SaveDialog1.Execute then
          begin
            FileName:=SaveDialog1.FileName;
            if (Copy(FileName,Length(FileName)-3,4)<>'.BAK') or (Copy(FileName,Length(FileName)-3,4)<>'.bak') then
              FileName:=FileName+'.BAK';
            ADOQ.SQL.Text:='Use Master Backup Database MES to Disk='''+ FileName+''' Use MES';
            ADOQ.ExecSQL;
            MessageDlg('數據庫備份成功!',mtInformation,[mbOK],0);
          end;
        except
          MessageDlg('數據庫備份失敗!',mtInformation,[mbOK],0);
          Exit;
        end;
      end;
    end;2.還原:procedure Tsys_datamodule.RestoreBaseBack;
    var
      StrFile:string;
      ADOQ:TADOQuery;
    begin
      ADOQ:=TADOQuery.Create(nil);
      ADOQ.Connection:=sys_datamodule.con1;
      if MessageDlg('你確定要還原數據庫嗎?',mtInformation,[mbYes,mbNo],0)=idyes then
      begin
        try
          if OpenDialog1.Execute then
          begin
            StrFile:=OpenDialog1.FileName;
            ADOQ.SQL.Text:='Use Master Restore Database MES From Disk='''+ StrFile+''' Use MES';
            ADOQ.ExecSQL;
            MessageDlg('數據庫還原成功!',mtInformation,[mbOK],0);
          end;
        except
          MessageDlg('數據庫還原失敗!',mtInformation,[mbOK],0);
          Exit;
        end;
      end;
    end;