views:

355

answers:

1

Hello. I've done a site using ASP.NET MVC, NHibernate and MySQL. In my project, I have some repositories classes, each one with methods using codes like this:

using(ISession session = NHibernateHelper.OpenSession()) {
    using(ITransaction transaction = session.BeginTransaction()) {
     session.Save(cidade);
     transaction.Commit();
    }
}

I come from Classic ASP, so I'm usure if the connection with MySQL is actually closed. In fact, I'm usure if there is a connection like there was on Classic ASP.

Should I do something to explicit close the connection/session or is it "autocloseable"?

There is a way to do if there are a lot of opened connection on my server?

Thank you very much.

+4  A: 

The session does the connection management in a very efficient way, so you don't have to do anything manually, as long as you don't forgot to dispose the session (like you do). The connection is not open during the whole lifetime of the session, but only when it's needed. There won't be more open connections to the database than the amount of connections in the connectionpool, which is 100 by default. 100 connections won't be to many in almost every scenario, so you don't need to do anything anything when a lot of connections are opened. On a very busy website, you even won't use all the 100 connections, it will be something like 20-40 open connections because of the size of the threadpool for the webrequests.

Paco