These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: available ADO DBConnection expires
PostPosted: Thu Feb 19, 2009 3:40 pm 
Newbie

Joined: Thu Feb 05, 2009 7:31 pm
Posts: 9
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;
            }
        }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.