user1599827
user1599827

Reputation:

How to get Nhibernate to break the physical connection to the database?

I'm connect to database using Nhibernate

_sessionFactory = configuration.BuildSessionFactory();
_sessionFactory = configuration.BuildSessionFactory();
_session = _sessionFactory.OpenSession(new DbInterceptor());
_sessionForSequenceQuery = _sessionFactory.OpenSession();
_sequenceQuery = _sessionForSequenceQuery.CreateSQLQuery("select nextval('sequence')");

when I need to disconnect from the database, I do

_sessionForSequenceQuery.Disconnect();
_session.Disconnect();
_sessionFactory.Dispose();

But the physical connection to the database remains. As I understand it breaks the physical connection is Nhibernate when it deems it necessary. How do I get him to do so immediately?

Upvotes: 1

Views: 1431

Answers (1)

outcoldman
outcoldman

Reputation: 11832

I guess that for _session you should invoke Close, not a Disconnect:

http://nhibernate.info/doc/nh/en/index.html#manipulatingdata-endingsession-close

The main implication of Close() is that the ADO.NET connection will be relinquished by the session.

http://nhibernate.info/doc/nh/en/index.html#transactions-disconnection

The method ISession.Disconnect() will disconnect the session from the ADO.NET connection and return the connection to the pool (unless you provided the connection).

Upvotes: 2

Related Questions