// Compact the database (which must be closed before // this method is called). If the database is not // periodically compacted it will keep getting bigger // and bigger. public void Compact() { try { String OriginalDBPath = GetDBFilePath(".MDB"); String CompactedDBPath = GetDBFilePath(".TMP"); // Delete the temporary file if it exists. try { File.Delete(CompactedDBPath); } catch (Exception) { } JetEngine J = new JRO.JetEngine(); // Compress the database (DATABASE.MDB) file to a temporary file // (DATABASE.TMP). J.CompactDatabase(GetConnectionString(), GetConnectionString(".TMP")); // Copy the compressed database file over the original database file. File.Copy(CompactedDBPath, OriginalDBPath, true); // Delete the temporary file. File.Delete(CompactedDBPath); } catch (Exception ex) { MessageBox.Show(ex.Message, Globals.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }