有数据库C:/a.mdb,在Acccess中打开时可以在资源管理器中复制和粘贴,但在程序中打开后,用filecopy "C:/a.mdb","D:/a.mdb"就会报错,必须关闭所有数据库连接的前提下才能备份成功。现求,在不关闭数据库的情况下也可备份数据库的方法,要兼容Win98、2K、XP

解决方案 »

  1.   

    呵,沙发!!    楼主,没用过ACCESS,给你SQL的数据库备份方法吧,自己琢磨一下,应该是相通的!
    Public Sub backup_Click(Index As Integer)
        Dim objSQLServer As New SQLDMO.SQLServer
        Dim strServer As String
        Dim strUserID As String
        Dim strPassword As String
        Dim strDatabase As String
        Dim strFile As String
        
        strServer = "192.168.1.188"            '你要备份的数据库服务器地址
        strUserID = "SA"
        strPassword = ""
        strDatabase = "storage"                '数据库名称
        strFile = "g:\mbd\database.bak"        '你希望备份文件的放置位置
        
        If Dir(strFile) <> "" Then
            If MsgBox("文件" & strFile & "已存在,是否删除?", vbQuestion + vbYesNo) = vbYes Then
                Kill strFile
            Else
                Exit Sub
            End If
        End If
        
        Screen.MousePointer = 11
        
        On Error GoTo ErrorHandler
        
        objSQLServer.Connect strServer, strUserID, strPassword
        
        Set objBackup = New SQLDMO.backup
        With objBackup
            .PercentCompleteNotification = 1
            .Database = strDatabase
            .Files = strFile
            .SQLBackup objSQLServer
        End With
        Set objBackup = Nothing
        
        objSQLServer.Close
        Set objSQLServer = Nothing
        
        Screen.MousePointer = 0
        Exit Sub
        
    ErrorHandler:
        Screen.MousePointer = 0
        MsgBox Err.Description, vbCritical
    End Sub
    Public Sub objBackup_Complete(ByVal message As String)
        MsgBox "备份成功!", vbOKOnly + vbExclamation, "提示"
        Set objBackup = Nothing
    End Sub
      

  2.   

    其实你可以先把你的CONN.CLOSE后再COPY这个是最保险的方法了
      

  3.   

    Access没有backup方法在多用户情况下,conn.close可能会造成其他工作站工作不正常。
      

  4.   

    Dim fso As FileSystemObject
        Set fso = New FileSystemObject
        fso.CopyFile "C:/a.mdb","D:/a.mdb"
    用这个,首先要引用microsoft script runtime
      

  5.   

    我记得有一个API函数可以在数据库打开的情况下copy这个数据库文件,以达到数据库备份!
      

  6.   

    直接用2进制方式打开文件进行读写:
    '备份e:\db1.mdb 为e:\db2.mdb
    Private Sub Command1_Click()
    Dim mfile As String, mfile2 As String
    mfile = "e:\db1.mdb"
    mfile2 = "e:\db2.mdb"
    Dim buff() As Byte
    Dim i As Long
    i = FileLen(mfile)
    ReDim buff(i - 1)
    Open mfile For Binary As #1
    Get #1, , buff
    Close #1
    Open mfile2 For Binary As #1
    Put #1, , buff
    Close #1
    MsgBox "ok"
    End Sub
      

  7.   

    要用到同步
    http://searchdatabase.techtarget.com.cn/tips/174/2054674.shtml
      

  8.   

    楼上程序测试通过,经20M文件测试表明,效率与filecopy无二至,已正式用到我的软件中。谢谢!
      

  9.   

    rainstormmaster(暴风雨 v2.0) 的程序测试通过,经20M文件测试表明,效率与filecopy无二至,已正式用到我的软件中。谢谢!结贴!