none
MS ACCESS COMPACT AND REPAIR IN C# PROGRAMMATICALLY RRS feed

  • Question

  • HI,

    how to compact and repair while using database... i need to compact and repair each half hour once in my application. My application is multi user based. can u any one tell me solution for this...


    Thanks & Regards,

    Thursday, October 22, 2015 2:14 PM

Answers

All replies

  • Use a database designed for multi user access, like Sql Server Express

    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    Thursday, October 22, 2015 4:24 PM
  • Thank you for reply...

    used following code for compact and repair programmatically

    public static void CompactAndRepair(string accessFile, Microsoft.Office.Interop.Access.Application app)
            {
                string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
                                  Path.GetRandomFileName() + Path.GetExtension(accessFile));
    
                app.CompactRepair(accessFile, tempFile, false);
                app.Visible = false;
    
                FileInfo temp = new FileInfo(tempFile);
                temp.CopyTo(accessFile, true);
                temp.Delete();
            }

    its works for single user but multi user getting error...

    Error : You Attempted to Open database that is already opened exclusively by user Admin.....

    any one tell me solution for this. i need to ms access compact & repair programmatically


    Thanks & Regards,

    Friday, October 23, 2015 4:40 AM
  • Exclusive use is required in order to compact an Access database. It is not possible to compact when multiple users have the database open.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, October 23, 2015 5:23 PM