怎么用delphi写数据库备份的程序啊?我按照sql server上的介绍编了一个,但老编不通,可能是我理解有问题吧,特来向各位大虾请教一下,怎么编写数据库备份的程序?谢谢!

解决方案 »

  1.   

    怎么几天这么多问备份的啊?
    看看以前的帖子吧
    你可以
    1 直接文件copy
    2 用back/restore database命令
    3 将back/restore database做成存储过程或者job然后调用
      

  2.   

    我以前写的:
    sBakFileName := '''' + 'c:\' + FormatDateTime('yyyy-mm-dd',Now) + '.bak' + '''';
    sBackupPath := 'BACKUP DATABASE ' + '[BankData] TO DISK=' + sBakFileName
      + ' WITH INIT,NAME = N' + '''' + 'DB备份' + '''';
    with DM1.QTemp do
      begin
        close;
        sql.Clear;
        sql.Add(sBackupPath);
        ExecSQL;
      end;
      

  3.   

    (8).备份和恢复
        procedure TForm1.Button1Click(Sender: TObject);
        begin
          if OpenDialog1.Execute then
          begin
            try
              adoconnection1.Connected:=False;
              adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=FRIEND-YOFZKSCO;'+
              'Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FRIEND-YOFZKSCO;Use Encryption for Data=False;Tag with column collation when possible=False';
              adoconnection1.Connected:=True;
              with adoQuery1 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('Backup DataBase sfa to disk ='''+opendialog1.FileName+'''');
                ExecSQL;
              end;
            except
              ShowMessage('±?·Y꧰ü');
            Exit;
            end;
          end;
          Application.MessageBox('1§?2?ú£?êy?Y±?·Y3é1|','ìáê?',MB_OK + MB_ICONINFORMATION);
        end;
        procedure TForm1.Button2Click(Sender: TObject);
        begin
          if OpenDialog1.Execute then
          begin
            try
              adoconnection1.Connected:=false;
              adoconnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=FRIEND-YOFZKSCO;'+
              'Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FRIEND-YOFZKSCO;Use Encryption for Data=False;Tag with column collation when possible=False';
              adoconnection1.Connected:=true;
              with adoQuery1 do
              begin
                Close;
                SQL.Clear;
                SQL.Add('Restore DataBase sfa from disk ='''+opendialog1.FileName+'''');
                ExecSQL;
             end;
           except
             ShowMessage('???′꧰ü');
             Exit;
           end;
         end;
         Application.MessageBox('1§?2?ú£?êy?Y???′3é1|','ìáê?',MB_OK + MB_ICONINFORMATION);
        end;