public string GetDifferences(string fromDatabase, string toDatabase) { string fromDatabaseSQL = GetSQL(fromDatabase); string toDatabaseSQL = GetSQL(toDatabase); try { System.IO.File.Delete("fromDB.sdf"); System.IO.File.Delete("toDB.sdf"); string fromConnectionString = string.Format("DataSource=fromDB.sdf;Persist Security Info=False;"); SqlCeEngine fromEngine = new SqlCeEngine(fromConnectionString); fromEngine.CreateDatabase(); using (System.Data.SqlServerCe.SqlCeConnection connection = new SqlCeConnection(fromConnectionString)) { connection.Open(); using (System.Data.SqlServerCe.SqlCeTransaction transaction = connection.BeginTransaction()) { using (System.Data.SqlServerCe.SqlCeCommand command = new System.Data.SqlServerCe.SqlCeCommand(fromDatabaseSQL, connection, transaction)) { command.ExecuteNonQuery(); transaction.Commit(); } } } string toConnectionString = string.Format("DataSource=toDB.sdf;Persist Security Info=False;"); SqlCeEngine toEngine = new SqlCeEngine(toConnectionString); using (System.Data.SqlServerCe.SqlCeConnection connection = new SqlCeConnection(toConnectionString)) { connection.Open(); using (System.Data.SqlServerCe.SqlCeTransaction transaction = connection.BeginTransaction()) { using (System.Data.SqlServerCe.SqlCeCommand command = new System.Data.SqlServerCe.SqlCeCommand(toDatabaseSQL, connection, transaction)) { command.ExecuteNonQuery(); transaction.Commit(); } } } return(CreateSqlDiffScript(fromConnectionString, toConnectionString)); } catch (Exception ex) { LOG.Error("Could not generate diff script.", ex); } finally { System.IO.File.Delete("fromDB.sdf"); System.IO.File.Delete("toDB.sdf"); } return(null); }
public void Commit() { try { _Transaction.Commit(); } catch (Exception ex) { throw new Exception("Não foi possível executar o commit da transação.", ex); } }