Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate exception: Transaction not connected, or was disconnected

In our develop environment all the ASP.NET application works just fine. However, when I deploy the site on the test machine, on some pages I get this exception:

NHibernate.TransactionException: Transaction not connected, or was disconnected
   at NHibernate.Transaction.AdoTransaction.CheckNotZombied() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:line 406
   at NHibernate.Transaction.AdoTransaction.Rollback() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:line 240

I have no idea on how to solve this issue. The only difference are the DB versions: Develop: 10.0.5500 (2008 R2, SP1, Express) Test: 10.0.5500 (2008, SP3)

Does someone has an idea what is going on here?

like image 224
Martijn Avatar asked Apr 08 '13 11:04

Martijn


2 Answers

This was a comment, but I had the same issue as well.

This error can occur when a trigger causes a database level exception. This will cause the transaction to be rolled back hence the exception.

like image 131
Daniel Little Avatar answered Nov 02 '22 01:11

Daniel Little


There's a problem with your session-per-request pattern implementation. ASP.NET is multi-threaded and the session is being closed when a thread terminates instead of when the request ends. There are many examples of how to manage session-per-request and NHibernate has a built in NHibernate.Context.WebSessionContext but I prefer to use a dependency injection framework such as Ninject.

like image 6
Jamie Ide Avatar answered Nov 02 '22 00:11

Jamie Ide