NHibernate and ADO.NET Connection Pooling

后端 未结 1 1196
抹茶落季
抹茶落季 2021-02-08 17:01

It seems that NHibernate does not pool ADO.NET database connections. Connections are only closed when the transaction is committed or rolled back. A review of the source code sh

相关标签:
1条回答
  • 2021-02-08 17:21

    NHibernate has two "modes".

    • Either you open the connection in your application, then it is up to the application to manage it. This "mode" is used when passing a connection to sessionfactory.OpenSession(connection).
    • Or the connection is created by NH. Then it is closed when the session is closed. This "mode" is used when not passing a connection to sessionfactory.OpenSession()

    There is some support for TransactionScope. It is most probably using the first "mode". Probably the connection is not hold by NH, but by the transaction scope. I don't know exactly, I don't use environment transactions.

    NH is using the ADO.NET connection pool by the way.

    You can also disconnect the session using ISession.Disconnect() and reconnect using ISession.Reconnect().

    In the documentation you find:

    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).

    0 讨论(0)
提交回复
热议问题