Hi Martijn,
I could be missing something, but I am not explicitly managing NH sessions. I assumed they were managed by using Castle.Facilities.NHibernateIntegration.ISessionManager. An example of our DAO method below makes use of Castle Transactions. Does this not Open a session, and then dispose the session when the theSessionObj object goes out of scope?
[Transaction(TransactionMode.Requires)]
public virtual void SaveOrUpdateEstimate(Domain.Estimate estObj)
{
ISession theSessionObj = this.m_sessionManager.OpenSession();
try {
theSessionObj.SaveOrUpdate(estObj);
}
catch (Exception ex) {
throw new ClException("JobManagementDao::SaveOrUpdateEstimate() Failed Transaction", ex);
}
}
With your help from a previous post -->
http://www.cuyahoga-project.org/home/forum.aspx?g=posts&t=684, I successfully re-purposed our Cuyahoga web application into a new console/service application. All is working fine except the MySQl DB connections are never being closed. I assumed the ‘Session per request’ pattern was being taken care of by the Castle/NH infrastructure?
Please comment on my assumptions/questions:
1) Since a console application has no ASP.NET page lifecycle, is this the main reason why our sessions/connections are not being closed? My console application never terminates, therefore the connections/sessions never close properly?
2) Without changing any code in the Cuyahoga.Core.DataAccess.CommonDao, should the method below properly close sessions/connections if this code was included and compiled into a properly built console application? I would assume it would, maybe that is my confusion. Does it only behave that way in a Web app (because its tied to an ASP.NET page lifecycle)?
[Transaction(TransactionMode.Requires)]
public virtual void SaveOrUpdateObject(object obj)
{
ISession session = this._sessionManager.OpenSession();
session.SaveOrUpdate(obj);
}
Thanks again,
Jmas