sergey wrote:
The most frequent source of such problems is building a new session factory for each request. Check that you are not doing it.
I just tested our data layer from which we are making every DAL in the project and i found this code.
Code:
try
{
cfg = new NHibernate.Cfg.Configuration();
cfg.Configure();
factory = cfg.BuildSessionFactory();
session = factory.OpenSession();
transaction = session.BeginTransaction();
}
catch (NHibernate.ADOException ex)
{
rollback();
DALDBException myDALDBException = new DALDBException(ex);
throw myDALDBException;
}
catch (NHibernate.HibernateException ex)
{
rollback();
DALHibernateInternalException myDALHibernateInternalException = new DALHibernateInternalException(ex);
throw myDALHibernateInternalException;
}
catch (Exception ex)
{
rollback();
DALException myDALException = new DALException(ex);
throw myDALException;
}
I attached a breakpoint on the first line of the try statement and found that even on the main page it is getting called 5 times... which means that we are building session factory for each request. is there a way where we can restrict the session factory from building multiple times without doing lot of code changes?