Reputation: 1249
I am getting the folloinwg error from NHibernate:
System.ObjectDisposedException: Session is closed! Object name: 'ISession'.
at NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed()
at NHibernate.Impl.AbstractSessionImpl.CheckAndUpdateSessionStatus()
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.Save(Object obj)
I am using NHibernate in .net windows service.
I am not able to trace the excact problem for the exception. This exception occurs very often.
Any one can help me on this to fix this exception?
nrk
Upvotes: 3
Views: 8547
Reputation: 7545
We had this same issue. Changing the App Pool Managed Pipeline to Classic solved it for us.
Upvotes: 0
Reputation: 12863
I am guessing you are wrapping your session in a using construct more than once, something like below. Can you post some of your session usage code?
HTH,
Berryl
Wrong - the session is closed after the first using construct:
using(var session = _sessionFactory.GetCurrentSession()
using(var tx = _session.BeginTransaction(){
... do something
tx.Commit();
}
using(var session = _sessionFactory.GetCurrentSession()
using(var tx = _session.BeginTransaction(){
... do something else
}
Better- the session is closed after it's work is done
var session = _sessionFactory.GetCurrentSession();
using(var tx = _session.BeginTransaction(){
... do something
tx.Commit();
}
using(var tx = _session.BeginTransaction(){
... do something else
tx.Commit()
}
session.Close()
Upvotes: 6
Reputation: 32391
As the error says - it looks like you are trying to save an object when your ISession is closed. Are you sure you are opening it? Or perhaps it is being closed prematurely?
Update: Have you checked the NHibernate Logs?
Upvotes: 2