We have an asp.net webforms application using NHibernate. Here are some features:
- We need distributed transactions because we write to the database, as well as to the queue.
- Since this is a web application, we use the recommended session in presentation template. We have an HTTPModule that opens an NHibernate session in the BeginRequest event and closes it at EndRequest.
- In the request flow, we have several separate points when we need to perform transactional work. For this we use TransactionScope.
So basically this happens (pseudo-code):
using(var session = sessionFactory.CreateSession()){
using(var tx1 = new TransactionScope(){
tx1.Complete();
}
using(var tx2 = new TransactionScope(){
tx2.Complete();
}
}
However, now we are in a situation where we see a lot of failures associated with connecting to the database. Some studies have given us two suggestions:
:
- NHibernate TransactionScope. NHibernate?
- TransactionScope, Session-in-view?