Many examples out there advocate explicit rollback of database transactions, along the lines of:
using (var transaction = ...)
{
try
{
// do some reading and/or writing here
transaction.Commit();
}
catch (SqlException ex)
{
// explicit rollback
transaction.Rollback();
}
}
However, I tend to do this:
using (var transaction = ...)
{
// do some reading and/or writing here
transaction.Commit();
}
When an exception occurs, I'm just relying on the implicit rolling back of transactions that aren't committed.
Is there any problem relying on this implicit behavior? Does anyone have a convincing reason why I shouldn't be doing it this way?