3

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

1
  • Yes.. I am opening the connection. Actually i am doing a file import application, in that I am doing record insertion batch-wise (200) with session and commiting the session and those records are available in DB also,, but after 2 or 3 batches it's giving this exception. I am not able to figure it out. Commented Mar 31, 2010 at 12:28

3 Answers 3

6

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()
Sign up to request clarification or add additional context in comments.

Comments

2

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?

4 Comments

looks similar like that, but making cascading= none fixed the issue.
Glad you got it working. If I were you though, I'd be sure to take a look at the nhibernate log4net logs, to maybe get some more info in whats going on, see: stackoverflow.com/questions/743323/nhibernate-enabling-log4net
@vapcguy See above link
@UpTheCreek - Thanks -- in other words, ensure you're logging them yourself, using log4NET, or other.
0

We had this same issue. Changing the App Pool Managed Pipeline to Classic solved it for us.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.