Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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});
        }