views:

44

answers:

0

I'm getting a the following exception:

"Timeout Expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled conections were in use and max pool size was reached."

...from a relatively heavily trafficked ASP.NET MVC 2 site I developed using StructureMap and Fluent NHibernate.

I think that perhaps the connections aren't being disposed properly. What do you think may be causing this? Could it be my use of InstanceScope.Hybrid?

Here's my NHibernateRegistry class; thanks in advance for your help:

using MyProject.Core.Persistence.Impl;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.ByteCode.LinFu;
using NHibernate.Cfg;
using MyProject.Core.FluentMapping;
using StructureMap.Attributes;
using StructureMap.Configuration.DSL;

namespace MyProject.Core.Persistence
{
    public class NHibernateRegistry : Registry
    {
        public NHibernateRegistry()
        {
            FluentConfiguration cfg = Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
                              x =>
                              x.FromConnectionStringWithKey(
                                  "MyConnectionString"))
                              .ProxyFactoryFactory(typeof (ProxyFactoryFactory).AssemblyQualifiedName))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<EntryMap>());

            Configuration configuration = cfg.BuildConfiguration();

            ISessionFactory sessionFactory = cfg.BuildSessionFactory();

            ForRequestedType<Configuration>().AsSingletons()
                .TheDefault.IsThis(configuration);

            ForRequestedType<ISessionFactory>().AsSingletons()
                .TheDefault.IsThis(sessionFactory);

            ForRequestedType<ISession>().CacheBy(InstanceScope.Hybrid)
                .TheDefault.Is.ConstructedBy(ctx => ctx.GetInstance<ISessionFactory>().OpenSession());

            ForRequestedType<IUnitOfWork>().CacheBy(InstanceScope.Hybrid)
                .TheDefaultIsConcreteType<UnitOfWork>();

            ForRequestedType<IDatabaseBuilder>().TheDefaultIsConcreteType<DatabaseBuilder>();
        }
    }
}