void CmdConvertClick(object sender, EventArgs e) { txtLog.Text = String.Format("Start Time: {0}", DateTime.Now.ToLongTimeString()); OdbcDba JetDb = new OdbcDba(); SQLiteDba SQLiteDb = new SQLiteDba(); try { File.Delete(this.SQLiteFile); } catch (IOException) { string Msg = String.Format("Cannot delete the existing SQLite file {0}", SQLiteFile); MessageBox.Show(Msg); return; } try { JetDb.ConnectMDB(this.JetSqlFile); } catch (OdbcException ex) { //TODO: this is the error code for incorrect access password. Make this a constant. if (ex.ErrorCode == -2147217843 || ex.ErrorCode == -2146232009) { DialogResult Result; InputDialog GetPassword = new InputDialog(); Result = GetPassword.ShowDialog("Enter the password for the database"); if (Result == DialogResult.OK) { try { ((OdbcDba) JetDb).ConnectMDB(JetSqlFile, GetPassword.Input); } catch (OdbcException exSecond) { if (ex.ErrorCode == -2147217843 || ex.ErrorCode == -2146232009) { MessageBox.Show("Incorrect Password"); } else { throw exSecond; } return; } finally { GetPassword.Dispose(); } } } else if (ex.ErrorCode == -2147467259) { Text = "PlaneDisaster.NET"; string Msg = String.Format("File [{0}] not found.", JetSqlFile); MessageBox.Show(Msg, "Error Opening File"); return; } else { throw ex; } } SQLiteDb.Connect(this.SQLiteFile); string [] Tables = JetDb.GetTables(); foreach (string Table in Tables ) { try { SQLiteDb.DataTable2SQLiteTable(JetDb.GetTableAsDataTable(Table)); } catch (OdbcException ex) { string Message = String.Format("{0}: {1}\n", Table, ex.Message); File.AppendAllText(String.Concat(SQLiteFile, ".log"), Message); } } JetDb.Disconnect(); SQLiteDb.Disconnect(); MessageBox.Show("Database Successfully converted."); txtLog.Text += String.Format(" End Time: {0}", DateTime.Now.ToLongTimeString()); }
public void TestSQLite() { string fileName = Path.Combine(_tempDirectory, _tempFilePrefix + ".sqlite"); try { CreateSQLite(fileName); SQLiteDba sqliteDba = new SQLiteDba(); sqliteDba.Connect(fileName); PopulateSQLite(sqliteDba); sqliteDba.ExecuteSqlCommand(_sqlDropTable); sqliteDba.Disconnect(); } finally { File.Delete(fileName); Assert.IsFalse(File.Exists(fileName), "Failed to delete " + fileName); } }