-->
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.  [ 2 posts ] 
Author Message
 Post subject: Connection remains open
PostPosted: Tue May 02, 2006 8:20 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
Hibernate version:

1.0.2.0
Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Tests.TestObj, Tests" table="TestObjs">
<id name="m_id" access="field" column="TestObjID">
<generator class="identity" />
</id>
<property name="m_name" access="field" column= "TestObjName"/>
</class>
</hibernate-mapping>

Code:
Code:
<Test()> _
    Public Sub CreateATransaction()
        Dim session As ISession
        Dim trx As ITransaction
        Try
            Dim sessionFactory As NHibernate.ISessionFactory
            Dim config As NHibernate.Cfg.Configuration
            config = New NHibernate.Cfg.Configuration
            config.AddAssembly("Tests")
            sessionFactory = config.BuildSessionFactory()
            session = sessionFactory.OpenSession()
            trx = session.BeginTransaction
            trx.Rollback()
   '         session.Connection.Close()
            session.Close()
            sessionFactory.Close()
            Assert.IsTrue(trx.WasRolledBack)
            Assert.IsFalse(session.IsOpen)
            Assert.IsFalse(session.IsConnected)
            trx = Nothing
            session = Nothing
            sessionFactory = Nothing
            config = Nothing
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub

Name and version of the database you are using:
MS SQL 2005

Hi there,

I don't have any error or something like that in my code, just a question.

When I run the code above everything works just fine. I open a session, a transaction, I rollback the thing close everthing I have to close and go on.

When I now open SQL Server Profiler, I still have an open connection to the database while I clearly told everything to close. If I close the program the connection will terminate but why exactly is that one connection still there and how can I make sure it does close?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 12:18 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I believe it's a side effect of ADO.NET connection pooling. To verify, try creating and closing a connection using plain ADO.NET without NHibernate - the behavior should be the same. Read the MSDN documentation to find out what you can do about this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.