I was performing big objects massive storaging and retrieving (several tables related between them). When i run (past) my unit tests, it drived to throw an error saying that ADO connection could not being open to my database.
I would like sharing with you the solution that i've found.
instead using following:
Code:
using (ISession _session = _sessionFactory.OpenSession())
{
try
{
/// All my session operations
}
finally
{
_session.Clear();
_session.Close();
//GC collection call here saves a lot of memory!!!!
GC.Collect();
}
}
I've realized that it's much more efficient if you store connection in a class property:
Code:
CheckDBConnection()
using (ISession _session = _sessionFactory.OpenSession(_dbConnection)
{
try
{
/// All my session operations
}
finally
{
_session.Clear();
_session.Close();
//GC collection call here saves a lot of memory!!!!
GC.Collect();
}
}
Where
Code:
void CheckDBConnection()
{
if ((_dbConnection == null) ||
(_dbConnection.State != ConnectionState.Open))
{
_dbConnection = _sessionFactory.OpenSession().Connection;
}
}