注册 | 登录

解决How to backup ms access database in

itPublisher 分享于



推荐:在VB.NET中使用MS Access存储过程(转载)

最新发布的MS Access中,微软已经尽努力使这种产品成为一个真正全功能的关系数据库系统。 存储过程,一个通常和企业数据库系统例如SQLServer相关的功能,现在也

How to backup ms access database in We're gonna make a system for a certain company but our teacher doesn't teach us at all, please help. Any idea on how to do it? ms-access
  this question
asked Dec 28 '09 at 11:45 user225269 3,858 47 138 215


3 Answers


The simplest way to make a backup of an Access-Database (or any one-file-databases) is to simply copy the file. But watch out for Exception because the file might be locked.

System.IO.File.Copy( _
    "C:\Your\original\database.mdb", _
    String.Format("D:\BackUps\{0:yyyyMMdd}.mdb", Date.Today) _

Additionally you could allow the user to specify the location and filename to which the file should be copied to. That's a rather trivial approach with simply utilizing the System.Windows.Forms controls OpenFileDialog and SaveFileDialog.

Using openDialog As New OpenFileDialog()
    openDialog.CheckFileExists = True
    openDialog.CheckPathExists = True
    openDialog.Filter = "Microsoft Access Database (*.mdb)|*.mdb"
    openDialog.RestoreDirectory = True

    Using saveDialog As New SaveFileDialog()
        saveDialog.CheckFileExists = False
        saveDialog.CheckPathExists = True
        saveDialog.FileName = Date.Now.ToString("yyyyMMdd") & ".mdb"
        saveDialog.Filter = "Microsoft Access Database (*.mdb)|*.mdb"
        saveDialog.RestoreDirectory = True

        If openDialog.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso saveDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            If File.Exists(openDialog.FileName) Then
                File.Copy(openDialog.FileName, saveDialog.FileName)
            End If
        End If
    End Using
End Using

In case you wonder what those RestoreDirectory property is doing: Those two dialogs are moving the current directory of the application to the designated paths, which might yield interesting effects later on if you assume a still unchanged current directory. To prevent this behavior, we set this property.

  this answer
edited Nov 27 '12 at 11:02 answered Dec 28 '09 at 11:57 Bobby 8,637 3 30 63 1   That's it. An Access database is just a Windows file, to do a backup just copy the file (either to a CD, DVD, external drive, or on a backup server). –  Meta-Knight Dec 28 '09 at 15:19 1   A file-system copy of a Jet/ACE data file may or may not be valid. It depends on whether or not users have it open and in a state that won't be properly copyable. The only reliable way to back it up is via the Jet/ACE database engine, which will never create an inconsistent copy. –  David-W-Fenton Dec 28 '09 at 22:00      @David: The question was, how to back it up...well, that's one way of doing it (at least in my eyes). He never specified any conditions to match. –  Bobby Dec 28 '09 at 22:59      thanks! maybe I could slightly change the code that you gave so that I could make it work with an open file dialog box? –  user225269 Dec 29 '09 at 23:03 3   I would assume that if you want to backup a file, you want that backup to be usable. Doing it with a file system copy may work 99% of the time, but it's that other 1% that's going to be an issue. –  David-W-Fenton Dec 30 '09 at 1:05  |  show more comments

Please, refer this: how to make backup and restore in vb[^]

推荐 access xml file

Imports System.Xml Module Module2     Sub main()         Dim xmlDoc As New XmlDocument()         xmlDoc.Load("e:\study\test.xml")         Dim root As

I'd suggest to use the MS Access compact database method. See: How to compact a Microsoft Access database by using Visual Basic .NETenter link description here

  this answer
edited Mar 9 '14 at 14:02 Olivier Jacot-Descombes 50k 7 53 99 answered Mar 8 '14 at 21:05 Maciej Los 4,521 1 9 21      See also How to compact a Microsoft Access database by using Visual Basic .NET on MSDN. –  Olivier Jacot-Descombes Mar 8 '14 at 21:20      @OlivierJacot-Descombes, i referenced it in my answer ;) –  Maciej Los Mar 8 '14 at 22:36      You did not include any link. I edited your answer to include the link. –  Olivier Jacot-Descombes Mar 9 '14 at 14:01      Follow the first link. There you'll find a reference to MS article ;) BTW: thank you, Olivier ;) –  Maciej Los Mar 9 '14 at 21:43      Are answers that just contain links elsewhere really “good answers”? –  Bobby Mar 10 '14 at 10:07

If File.Exists(openDialog.FileName) Then
                File.Copy(openDialog.FileName, saveDialog.FileName)
            End If I GOT ERROR ON THIS

  this answer
edited Aug 3 '16 at 4:16 manetsus 3,222 9 21 44 answered Aug 3 '16 at 4:09 asdasdasd 1


推荐:Working with MS Access Stored Procedures in VB.NET Montaque(转贴)

Working with MS Access Stored Procedures in VB.NET. Part 1 by David Wasserman, MCP 2/27/2002 Article source code: Introduction In the








您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱