Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5979929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:43:46+00:00 2026-05-22T21:43:46+00:00

When I open a session with var session = factory.OpenSession(); and check session.Connection.State it

  • 0

When I open a session with

var session = factory.OpenSession();

and check session.Connection.State it is Open. The “Connection” is of type SqlConnection.
This means that by creating the session the connection is automatically opened, which I thought that with NH isn’t the case. Shouldn’t this be closed until NH determines the optimal time for flush? What am I doing wrong?

The hibernate.cfg.xml:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=Test; Integrated Security=SSPI</property>
    <property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
  </session-factory>
</hibernate-configuration>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:43:47+00:00Added an answer on May 22, 2026 at 9:43 pm

    No, what actually happens is that NHibernate creates and opens a connection when you first say session.Connection (if the session didn’t already have a connection, of course)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to check if a user has an open Facebook session
I have the following code factory = new Configuration().Configure().BuildSessionFactory(); session = factory.OpenSession(); var query
When I invoke the SessionFactory.OpenSession() method a session is created, which contains a open
i'm trying to understand how and if its possible to keep a session open
Suppose I want to open a file in an existing Emacs session using su
I almost always have a Scala REPL session or two open, which makes it
In an interactive session like the following one: >>> f=open('test.txt','w') >>> f <open file
Open up a Rails console and enter this: 2.weeks.ago.between? 2.weeks.ago, 1.week.ago Did it give
In this question I asked about NHibernate session lifetime. I'm using a desktop application,
is it possible to set a session var from apache? i mean i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.