各位兄弟请帮看一下在我备份数据库时老是出现错误代码如下:procedure TForm1.Button2Click(Sender: TObject);
begin
  with Query1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('backup database ghome TO disk "c:\yu\home.bak"');
    ExecSQL;
  end;
end;

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      filename:string;
    begin
      statusbar1.SimpleText :='正在备份中.....';
      Filename:='pubs' + formatDatetime('yyyy-mm-dd',now);
      adoconnection1.Close ;
      begin
      try
        adocommand1.CommandText :='use master';
        adocommand1.Execute ;
        adocommand1.CommandText :='execute sp_helpdevice';
        adocommand1.Execute ;
        adocommand1.CommandText :='backup database pubs to disk='''+'f:\'+filename+''' with init';
        adocommand1.Execute ;
        adocommand1.CommandText :='use pubs';
        adocommand1.Execute ;
      //  application.MessageBox(pchar('backup database ok'+filenamegsysname,mb_ok+mb_iconinfomation);
        application.MessageBox('数据库已经成功备份到','系统对话框',mb_ok);
        try
          ADOConnection1.Connected :=true;
        except
          begin
            statusbar1.SimpleText :='';
            Application.MessageBox('连接数据库错误','asd',MB_OK+mb_iconerror);
            abort;
            end;
          end;
        except
          on Exception do
            if adoconnection1.InTransaction then
              adoconnection1.RollbackTrans ;
        end;
      end;
    end;我用这个备份,你试一下吧
      

  2.   

    我是用ADOCOMMAND实现远程备份数据库的,我看了一下,感觉不应该使用双引号应为:
    'backup database ghome TO disk ''c:\yu\home.bak''')
      

  3.   

    l_SQL := 'BACKUP DATABASE PAMS' +  ' TO DISK = ' +
                         QuotedStr(BackupFileName) + ' WITH INIT'; 
    SQL.Add(l_SQL);