-->
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.  [ 3 posts ] 
Author Message
 Post subject: mysql how to close connections
PostPosted: Tue Nov 28, 2006 5:11 pm 
Newbie

Joined: Sat Nov 25, 2006 5:07 pm
Posts: 3
hi all
i would like toknow how we need to close connections opened by nhibernet to a mysql db

Dispose() is not available on connections obtained from SessionFactory.OpenSession(). At least not in vb.net...
we use Close() instead, at the present.

this gives us unclosed connections after a while.
how can we solve this issue?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 5:51 am 
Beginner
Beginner

Joined: Wed Nov 22, 2006 5:59 am
Posts: 29
Location: London
You could use as a using statement to ensure that the resource is released after use. E.g.

Code:

public void SaveItem(Item item)
{
            using (ISession session = NHibernateHelper.SessionFactory().OpenSession())
            {
                ITransaction transaction = session.BeginTransaction();
                try
                {
                    session.Save(item);
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                }
            }
}


This way the session will be closed for you etc.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 3:02 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
But that does not necessarily physically close the connection since it is pooled. As far as I know there is no way to do what the OP wants except by turning off connection pooling.


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

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.