This is my nh configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
    <property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
    <property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
    <property name="connection.connection_string">Data
Source=server;Initial Catalog=database;User ID=abc;Password=abc</
property>
    <property name ="connection.isolation">ReadCommitted</property>
    <property name="default_schema">database.dbo</property>
    <property name="show_sql">true</property>
    <property name="generate_statistics">true</property>
    <property name="format_sql">true</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</
property>
    <property
name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
NHibernate.ByteCode.LinFu</property>
    <mapping assembly="database.Data.Objects"/>
  </session-factory>
</hibernate-configuration>

I have implemented a unit of work pattern:

using (var workUnit = new UnitOfWork())
            {
                try
                {
                    var provider = new ProfessionProvider
(workUnit.Session);

                    return provider.GetProfessions();
                }
                catch (HibernateException)
                {
                    workUnit.RollbackTransaction();
                    throw;
                }
            }

this implments the IDisposable interface.
In the constructor i get a session from the sessionmanager and begin a
transaction.
Disposing:

private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    //Dispose of the Transaction Object
                    DisposeTransaction();
                    DisposeSession();
                }
            }

            _disposed = true;
        }

        /// <summary>
        /// Disposes the transaction.
        /// </summary>
        private void DisposeTransaction()
        {
            if (Transaction == null)
            {
                return;
            }

            CommitTransaction();

            Transaction.Dispose();
        }

        private void DisposeSession()
        {
            CloseSession();
            Session.Dispose();
        }

private void CloseSession()
        {
            if (Session.IsOpen)
            {
                Session.Close();
            }
        }

Is there something wrong???
What do you think???

regards

On Jul 17, 3:23 pm, Oskar Berggren <[email protected]> wrote:
> Read up on connection pooling. This is in ADO.NET and works
> independently of NHibernate. You might wanna adjust your connection
> string (for your tests, not production).
>
> /Oskar
>
> 2009/7/17 Fabio Maulo <[email protected]>:
>
> > you are doing something wrong... there isn't a open connection even with an
> > open-session.
>
> > 2009/7/17 mantzas <[email protected]>
>
> >> Hi,
>
> >> a quick question about the onnetions that are opened.
>
> >> I reated a singleton for the sessionFatory. I implemented the unit o
> >> work pattern that gets the session from the fatory and releases it.
>
> >> AFAIK connetions are opened and closed within this context only.
>
> >> I have build a WCF service which is used by the client.
>
> >> I wrote a unit test for this service.
>
> >> In order to revert the database to a known state i used sql server
> >> snapshots.
>
> >> This is where the tests abort since it cannot restore a database that
> >> has a active connection.
>
> >> Active connection??? I though there is no active connetion after the
> >> session closes.
>
> >> Has someone an answer to that????
>
> >> Thx
>
> > --
> > Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to