Skip to content

Commit

Permalink
Merge pull request #211 from jzabroski/topic/209
Browse files Browse the repository at this point in the history
Respect transaction flag, rollback on error.  Fixes issues #209 and...
  • Loading branch information
ChrisMissal committed Aug 17, 2015
2 parents b37ebcf + 1beef0a commit de4d86a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions product/roundhouse/databases/AdoNetDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,32 @@ protected override void run_sql(string sql_to_run, ConnectionType connection_typ
}
catch (SqlException ex)
{
if (ex.Number == sql_connection_exception_number)
// If we are not running inside a transaction, then we can continue to the next command.
if (transaction == null)
{
// But only if it's a connection failure AND connection failure is the only error reported.
if (ex.Errors.Count == 1 && ex.Number == sql_connection_exception_number)
{
Log.bound_to(this).log_a_debug_event_containing("Failure executing command, trying again. {0}{1}", Environment.NewLine, ex.ToString());
run_command_with(sql_to_run, connection_type, parameters);
Log.bound_to(this).log_a_debug_event_containing("Failure executing command, trying again. {0}{1}", Environment.NewLine, ex.ToString());
run_command_with(sql_to_run, connection_type, parameters);
}
else
{
//Re-throw the original exception.
throw;
//Re-throw the original exception.
throw;
}
}
else
{
// Re-throw the exception, which will delegate handling of the rollback to DatabaseMigrator calling class,
// e.g. DefaultDatabaseMigrator.run_sql(...) method catches exceptions from run_sql and rolls back the transaction.
throw;
}
}
catch (Exception ex)
{
// If the Exception is not due to a SqlException, which is the case for any non-SqlServer database, then also delegate handling of the rollback to DatabaseMigrator calling class.
throw;
}
}

Expand Down

0 comments on commit de4d86a

Please sign in to comment.