ms-accesscompact-database

compact ms access database in vb.net without copy of the database


I have searched the net on this topic and found, that if an ms access database should be compacted, then I should give the database itself and a new path.

Why is this necessary? If I check in ms access, that it should compact the database after closing, it don't creates a compacted database and deletes the old one, but it compacts only the one database. Or it is so fast, that I can't see it?


Solution

  • Access creates the compacted db as a new file, deletes the old (uncompacted) db file, and renames the new file to the old name.

    It always works that way regardless of whether you compact from external code, from within an active Access session, or with compact on close at the end of an Access session.

    With a small enough db file, the entire process can complete so quickly that you might not notice the transitional new db file. But with a large enough db file --- 1 GB should do it --- you can watch in Windows Explorer as the new db file is created and grows to it final (compacted) size.

    Incidentally, be cautious about compact on close. Many experienced Access developers recommend against that option. The reason is that if anything goes wrong during compact, the new db can be corrupted and your original uncompacted version will be gone ... so no hope of recovery.