Thanks for your response!

Nested TransactionScope objects do not necessarily mean nested
transactions, just that a particular block of code should participate
in a transaction, either by creating a new ambient transaction, or
using the existing one (http://msdn.microsoft.com/en-us/library/
system.transactions.transactionscope.aspx).  From what I understood,
NH 3.x supports TransactionScope.  Ideally I would just use
TransactionScope, but NHibernate will leak connections to SQL Server
2005 on a rollback (http://davybrion.com/blog/2010/05/avoiding-leaking-
connections-with-nhibernate-and-transactionscope/), so I need to also
manage an NHibernate transaction.

I need to be able to manage transactions outside of the actual
database access code so that the outermost calling code actually
demarcates the transaction boundary.  I am using WCF so ideally I
would just annotate my service operations with
TransactionScopeRequired and TransactionAutoComplete attributes.  If
you are suggesting I forego TransactionScope altogether, I would need
to implement my own equivalent attribute that manages both an
NHibernate ISession as well as an NHibernate ITransaction.  That just
seems like overkill..

On Nov 22, 7:14 am, Jason Meckley <[email protected]> wrote:
> The first problem I see is nested transactions. don't nest them. you only
> need one. if you are using a system transaction then instantiate the
> transaction before you open the session
> using(var tx = new TransactionScope())
> using(var session = factory.OpenSession()
> {
>    do work
>    tx.Complete();
>
> }
>
> if you are using NH 3.x that's all you need. if you are using NH 2.x you
> still need to manage the NH transaction to prevent a memory leak when a
> system transaction does not complete.
>
> However, since you don't need distributed transactions, I would drop the
> system transaction all together and stick with NH transaction
> using(var session = factory.OpenSession())
> using(var tx = session.BeginTransaction
> try
> {
>    do work
>    tx.Commit();}
>
> catch
> {
>    tx.Rollback();
>    throw;
>
> }
>
> Again, do not nest transactions.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to