none
How can i make a backup of an Access Database through a C# interface ?? RRS feed

  • Question

  • how can i make a backup of an Access database using a C# interface which the user requires to specify the destination of the backup file?
    Saturday, May 10, 2008 9:30 AM

Answers

  • I would suggest using JRO (Jet Replication Objects). Keep in mind the database will need to be closed before you create the backup.

    http://www.codeproject.com/KB/database/mdbcompact_latebind.aspx



    Thursday, May 15, 2008 3:17 PM

All replies

  • The easiest thing would be to use standard File I/O and copy the mdb file. But you can make a backup and compact/repair the database with COM Interop. The database would have to have no connections to do this.

     

    In you project add a reference to the COM library - Microsoft Access Object Library 11.0 (or whatever version you have...)

     

    Code Snippet

    using System;

    using System.Collections.Generic;

    using System.Text;

    using Microsoft.Office;

    namespace AccessInterop

    {

    class Program

    {

    static void Main(string[] args)

    {

    Access.Application oAccess = new Access.ApplicationClass();

    try

    {

    oAccess.DBEngine.CompactDatabase("c:\\testingground\\db1.mdb",

    "c:\\testingground\\backup.mdb", null, null, null);

    }

    catch(COMException ce)

    {

    \\Database open, cannot compact

    }

    }

    }

    }

     

     

    Saturday, May 10, 2008 11:28 AM
  • I do not think BACKUP DATABASE statement is valid with Access database and it is supported with Access. Access is not server-type database and to make backup copy of it you need to make a simple copy of the file without connecting to it. You could use CopyTo method of FileInfo class to copy existing mdb file into another one and make backup copy of it.

     

    Monday, May 12, 2008 11:28 PM
    Moderator
  • I would suggest using JRO (Jet Replication Objects). Keep in mind the database will need to be closed before you create the backup.

    http://www.codeproject.com/KB/database/mdbcompact_latebind.aspx



    Thursday, May 15, 2008 3:17 PM