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); } }
private static void PopulateOleDba(OleDba oleDba) { tblTestRow [] rows = new tblTestRow [] { new tblTestRow(1, "Number one."), new tblTestRow(2, "Number two."), new tblTestRow(3, "Number three.") }; oleDba.ExecuteSqlCommand(_sqlCreateTable); foreach(tblTestRow row in rows) { DbParameter[] parameters = new DbParameter [] { new OleDbParameter("@id", row.Id), new OleDbParameter("@description", row.Description) }; oleDba.ExecuteSqlCommand(_sqlInsertRow, parameters); } string [] columnData = oleDba.GetColumnAsStringArray("tblTest", "description"); Assert.AreEqual(columnData.Length, 3, "Inserted 3 rows and retrieved {0}", new object[] {columnData.Length}); }
public void TestProcedureSupport() { string fileBaseName = Path.Combine(_tempDirectory, _tempFilePrefix); OleDba oleDba = null; try { CreateMdb(fileBaseName + ".mdb"); oleDba = new OleDba(); try { Assert.IsTrue(oleDba.SupportsProcedures); Assert.Fail("OleDba.SupportsProcedures should throw a InvalidOperationException if no database is connected."); } catch(InvalidOperationException) {} oleDba.ConnectMDB(fileBaseName + ".mdb"); Assert.IsTrue(oleDba.SupportsProcedures);; } finally { if (oleDba != null && oleDba.Connected) { oleDba.Disconnect(); oleDba.Dispose(); } File.Delete(fileBaseName + ".mdb"); Assert.IsFalse(File.Exists(fileBaseName + ".mdb"), "Failed to delete " + fileBaseName + ".mdb"); } }