public void TestCompactMdb() { string fileName = Path.Combine(_tempDirectory, _tempFilePrefix + ".mdb"); OleDba oleDba = null; try { CreateMdb(fileName); oleDba = new OleDba(); oleDba.ConnectMDB(fileName); PopulateOleDba(oleDba); oleDba.Disconnect(); JetSqlUtil.CompactMDB(fileName); oleDba.ConnectMDB(); oleDba.ExecuteSqlCommand(_sqlDropTable); oleDba.Disconnect(); } finally { if (oleDba != null && oleDba.Connected) { oleDba.Disconnect(); oleDba.Dispose(); } File.Delete(fileName); Assert.IsFalse(File.Exists(fileName), "Failed to delete " + fileName); } }
void menuCompactDatabase_Click(object sender, System.EventArgs e) { FileDialog dlg = new OpenFileDialog(); dlg.Filter = FILTER_JETSQL; try { if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.FileName == CurrentFile) { DisconnectDataSource(); JetSqlUtil.CompactMDB(dlg.FileName); OpenMDB(CurrentFile); } else { JetSqlUtil.CompactMDB(dlg.FileName); } } } catch (ApplicationException) { StringBuilder ErrorMessage = new StringBuilder(); ErrorMessage.AppendFormat ("There seems to be a problem compacting {0}.\n", dlg.FileName); ErrorMessage.AppendLine ("Perhaps the file is opened by another process."); MessageBox.Show(ErrorMessage.ToString(), "PlaneDisaster.NET"); } dlg.Dispose(); }
private static void CompactAndRepairMdb(string fileName) { JetSqlUtil.CompactMDB(fileName); JetSqlUtil.RepairMDB(fileName); }