Hi i really need code to back up an access database. Am using visual studio 2005. i have to submit my project next week..
please help me. I want to place the code in a button back up..

Dani AI

Generated

’s suggestion (copy the .mdb) is the quickest way, but there are important caveats and safer alternatives you should consider before your submission.

Always close and dispose every database connection before attempting a backup; a locked or pooled connection will make a simple file copy fail or produce an inconsistent file. In VB.NET prefer Using so connections are closed reliably:

Using cn As New System.Data.OleDb.OleDbConnection(connString)
    cn.Open()
    ' perform DB work here
End Using
' At this point the connection is closed and disposed

If you need a more robust backup (and want the copy compacted at the same time) use the Jet Replication Objects (JRO) compact method to create a fresh copy. Add a COM reference to “Microsoft Jet and Replication Objects” and run:

' Requires a reference to the JRO COM library
Dim jro As New JRO.JetEngine()
jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\MyDB.mdb;",
                    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\backups\MyDB_backup.mdb;")

Notes and practical tips:

  • JRO targets Jet (.mdb). For .accdb (ACE) you’ll need the ACE provider or DAO/Access interop; avoid Office automation on IIS—Microsoft does not recommend automating Access/Office from server-side code.
  • For web apps, schedule backups during low traffic or recycle the app pool so no connections remain.
  • Use timestamped filenames, keep a rotation (N copies), and always verify a backup by opening it read‑only before deleting older copies.
    These steps will help you move from the simple copy idea toward a reliable backup process suitable for development and small deployments.

Recommended Answers

All 2 Replies

just copying a .mdb file to backup folder.

commented: Right +1
commented: Nice +1

the easiest way is copying current access database to backup folder.
Use FileCopy to copying file.
this following code is an example :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FileCopy("D:\Authors.mdb", "D:\BackUpFolder\NewBackUpName.mdb")
End Sub

So file Authors.mdb in D:\ will copying into Folder BackUpFolder

commented: Nice way :) +1
commented: good idea +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.