The following code executes one stored procedure. The stored procedure has only one command in it. Is there any benefit to wrapping everything in a transaction, even it only has one SQL statement in it (or one stored proc that has only one sql statement)?
In the sample code below, if the delete fails, it fails. There is nothing else to be rolled back (it seems). So why is everything wrapped in a transaction anyhow?
using (ITransactionManager transMan = repository.TransactionManager())
using (IController controller = repository.Controller())
{
transMan.BeginTransaction();
try
{
//DELETE FROM myTable where Id=@id
controller.Delete(id);
transMan.CommitTransaction();
}
catch
{
transMan.RollbackTransaction();
throw;
}
}