Roll back transaction when error occurs

6 views
Skip to first unread message

Sly

unread,
Apr 26, 2009, 10:29:48 AM4/26/09
to S#arp Architecture
Isn't it a good idea to roll back the transaction when unhandled
exception occurs?
In current version of Transaction attribute there is begin of the
transaction but there is no rollback.
I've had a problem when error occurred and table was locked until
transaction timeouts or I restart sql server instance.
I have modified TransactionAttribute code
public override void OnActionExecuted(ActionExecutedContext
filterContext)
{
if(NHibernateSession.Current.Transaction.IsActive)
{
if (filterContext.Exception != null)
NHibernateSession.Current.Transaction.Rollback();
else
NHibernateSession.Current.Transaction.Commit();
}
}
Now there is now active transactions left.
How do you think?

Billy

unread,
Jun 17, 2009, 12:24:28 AM6/17/09
to S#arp Architecture
Great catch Sly...and thanks for the patch. I'm currently applying it
to the trunk.

Billy
Reply all
Reply to author
Forward
0 new messages