如何在程序中备份和恢复正在使用的ACCESS数据库?

解决方案 »

  1.   

    手工做个吧,access没有这方面的功能
    方法是:
    1。创建数据库
    2。复制表
      

  2.   

    其实也不用那么麻烦去创建数据库复制表直接关闭数据库连接,用copyfile拷贝也行 ,如:copyfile('C:\data1.mdb','d:\data1.mdb',false);   
    哈~~~
      

  3.   

    给你一个现成的哈..
       
      var   
          MyFileName:   string;   
      begin   
          MyFileName   :=   '';   
          try   
          if   SaveDialog1.Execute   then   
          begin   
              MyFileName   :=   SaveDialog1.FileName;   
              if   MyFileName   <>   ''   then   
              begin   
                  if   CopyFile(Pchar(ExtractFilePath(Application.ExeName)   +   'shoufa.mdb'),   Pchar(MyFileName),   false)   then   
                  begin   
                      Application.MessageBox('数据备份成功','提示',Mb_ok   +   mb_iconinformation);   
                  end;   
              end;   
          end;   
          except   
              Application.MessageBox('数据备份失败','提示',Mb_ok   +   mb_iconError);   
          end;   
      恢复:   
      var   
          MyFileName,   aa:   string;   
      begin   
          MyFileName   :=   '';   
          try   
              if   OpenDialog1.Execute   then   
              begin   
                  MyFileName   :=   OpenDialog1.FileName;   
                  if   MyFileName   <>   ''   then   
                  begin   
                      aa   :=   ExtractFilePath(Application.ExeName)   +   'shoufa.mdb';   
                      if   CopyFile(Pchar(MyFileName),Pchar(aa),   false)   then   
                      begin   
                          DataM.ADOConnection1.Close;   
                          DataM.ADOConnection1.Open;   
                          Application.MessageBox('数据恢复成功','提示',Mb_ok   +   mb_iconinformation);   
                      end;   
                  end;   
              end;   
          except   
              Application.MessageBox('数据恢复失败','提示',Mb_ok   +   mb_iconError);   
          end;