请看以下面的方法备份数据库为什么不行:
unit Unit1;interfaceuses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, Grids, DBGrids, DB, DBClient,MIDASLIB, SimpleDS, SqlExpr,
 DBXpress,ShellAPI;type
 TForm1 = class(TForm)
  SQLConnection1: TSQLConnection;
  SimpleDataSet1: TSimpleDataSet;
  datasource1: TDataSource;
  btnConnect: TButton;
  btnQuery: TButton;
  DBGrid1: TDBGrid;
  lbl1: TLabel;
  Edit1: TEdit;
  Edit2: TEdit;
  Button1: TButton;
  Button2: TButton;
  OpenDialog1: TOpenDialog;
  SaveDialog1: TSaveDialog;
  Button3: TButton;
  procedure btnConnectClick(Sender: TObject);
  procedure btnQueryClick(Sender: TObject);  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
  procedure Button3Click(Sender: TObject);
 private
  { Private declarations }
 public
  { Public declarations }
 end; function FixPathStr(path: string): string;
var
 Form1: TForm1;implementation{$R *.dfm}function FixPathStr(path: string): string;
begin
 if pos(' ', path) = 0 then
  Result := path
 else
  Result := '"'+ path+ '"';
end;procedure TForm1.btnConnectClick(Sender: TObject);
begin
 if SQLConnection1.Connected=true then
  SQLConnection1.Connected:=false;
 SQLConnection1.Params.Clear;
 SQLConnection1.Params.values['user_name']:='sysdba';
 SQLConnection1.Params.values['password']:='masterkey';
 sqlConnection1.Params.values['SQLDialect']:='3';
 SQLConnection1.Params.values['database']:=extractfilepath(paramstr(0))+'data\demo.fdb';
 SQLConnection1.Connected:=true;
 showmessage('连接成功');
end;procedure TForm1.btnQueryClick(Sender: TObject);
begin
 if not sqlConnection1.Connected then
 begin
  showmessage('请先连接');
  exit;
 end; SimpleDataSet1.DataSet.CommandText:='select * from STUDENT';
 simpleDataSet1.Open;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin if OpenDialog1.Execute then
  Edit1.Text:= OpenDialog1.FileName;
end;procedure TForm1.Button2Click(Sender: TObject);
begin if SaveDialog1.Execute then
  Edit2.Text := SaveDialog1.FileName;
end;procedure TForm1.Button3Click(Sender: TObject);
var
 fdb, fbk, CmdLines, binpath: string;begin  fdb := FixPathStr(Edit1.Text);
  fbk := FixPathStr(Edit2.Text);
  binpath := ExtractFilePath(Application.ExeName);
  CmdLines := Format(' %s gbak -v -t -user SYSDBA -password "masterkey" %s %s',
     [binPath, fdb, fbk]);
  ShellExecute(handle, 'open', pchar('cmd'), pchar(CmdLines), pchar(binPath), SW_HIDE);
end;end.
使用gbak备份数据库语句如下:
gbak -v -t -user SYSDBA -password masterkey 'D:\temp\testdb.fdb' 'D:\temp\testdb.fbk';
以上D:\temp\testdb.fdb是数据库文件的路径,D:\temp\testdb.fbk是备份文件的存放路径。

解决方案 »

  1.   

    在网上搜过基本都是下面这样:
    CmdLines := Format(' /c gbak -v -t -user SYSDBA -password "masterkey" %s %s',
              [fdb, fbk]);但是使用gbak备份数据库语句如下:
    gbak -v -t -user SYSDBA -password masterkey 'D:\temp\testdb.fdb' 'D:\temp\testdb.fbk';
    以上D:\temp\testdb.fdb是数据库文件的路径,D:\temp\testdb.fbk是备份文件的存放路径。
     
     
     
    因此做了如下的修改,可是改成下面这样也不行,应用程序没有与数据库连接,这个数据库是嵌入版的。
    unit Unit1;interfaceuses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, Grids, DBGrids, DB, DBClient,MIDASLIB, SimpleDS, SqlExpr,
    DBXpress,ShellAPI;type
    TForm1 = class(TForm)
     SQLConnection1: TSQLConnection;
     SimpleDataSet1: TSimpleDataSet;
     datasource1: TDataSource;
     btnConnect: TButton;
     btnQuery: TButton;
     DBGrid1: TDBGrid;
     lbl1: TLabel;
     Edit1: TEdit;
     Edit2: TEdit;
     Button1: TButton;
     Button2: TButton;
     OpenDialog1: TOpenDialog;
     SaveDialog1: TSaveDialog;
     Button3: TButton;
     procedure btnConnectClick(Sender: TObject);
     procedure btnQueryClick(Sender: TObject); procedure Button1Click(Sender: TObject);
     procedure Button2Click(Sender: TObject);
     procedure Button3Click(Sender: TObject);
    private
     { Private declarations }
    public
     { Public declarations }
    end;function FixPathStr(path: string): string;
    var
    Form1: TForm1;implementation{$R *.dfm}function FixPathStr(path: string): string;
    begin
    if pos(' ', path) = 0 then
     Result := path
    else
     Result := '"'+ path+ '"';
    end;procedure TForm1.btnConnectClick(Sender: TObject);
    begin
    if SQLConnection1.Connected=true then
     SQLConnection1.Connected:=false;
    SQLConnection1.Params.Clear;
    SQLConnection1.Params.values['user_name']:='sysdba';
    SQLConnection1.Params.values['password']:='masterkey';
    sqlConnection1.Params.values['SQLDialect']:='3';
    SQLConnection1.Params.values['database']:=extractfilepath(paramstr(0))+'data\demo.fdb';
    SQLConnection1.Connected:=true;
    showmessage('连接成功');
    end;procedure TForm1.btnQueryClick(Sender: TObject);
    begin
    if not sqlConnection1.Connected then
    begin
     showmessage('请先连接');
     exit;
    end;SimpleDataSet1.DataSet.CommandText:='select * from STUDENT';
    simpleDataSet1.Open;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    beginif OpenDialog1.Execute then
     Edit1.Text:= OpenDialog1.FileName;
    end;procedure TForm1.Button2Click(Sender: TObject);
    beginif SaveDialog1.Execute then
     Edit2.Text := SaveDialog1.FileName;
    end;procedure TForm1.Button3Click(Sender: TObject);
    var
    fdb, fbk, CmdLines, binpath: string;begin fdb := FixPathStr(Edit1.Text);
     fbk := FixPathStr(Edit2.Text);
     binpath := ExtractFilePath(Application.ExeName);
     CmdLines := Format('gbak -v -t -user SYSDBA -password "masterkey" %s %s',
       [fdb, fbk]);
     ShellExecute(handle, 'open', pchar('cmd'), pchar(CmdLines), pchar(binPath), SW_HIDE);
    end;end.
      

  2.   

    Firebird 自带 Delphi 套件库,叫 FIBPlus,那里面有备份功能。
    怎么用查帮助。