i created a web application by using Asp.NET webform, NHibernate to access Sql Server 2008 database and StructureMap as IOC Container.
Everything seem to work ok since few users use it; when user number increases (we can say 10+ users) webapp crashes with this error:
System.OutOfMemoryException
I downloaded redgate ants suite: the performance tool says that maximum cpu time is in NHibernate createSessionFactory for a GetAll request.
This is my NHibernateHelper object:
public static NHibernate.ISessionFactory _sessionFactory;
public static NHibernate.ISessionFactory createSessionFactory()
{
try
{
if (_sessionFactory == null)
{
return
FluentNHibernate.Cfg.Fluently.Configure()
.Database
(
FluentNHibernate
.Cfg.Db.MsSqlConfiguration.MsSql2008
.ConnectionString
(
c => c
.Server(ConfigurationManager.DbConnectionValue.Server)
.Username(ConfigurationManager.DbConnectionValue.User)
.Password(ConfigurationManager.DbConnectionValue.Password)
.Database(ConfigurationManager.DbConnectionValue.Database)
)
.ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu")
)
.Mappings
(
m => m.FluentMappings.AddFromAssemblyOf<Repository.IRepositoryBlocco>()
)
.BuildSessionFactory();
}
else
return _sessionFactory;
}
catch (Exception ex)
{
throw ex;
}
}
This is the way i read data from db:
public IList<DomainModel.Model.Variabile> GetAll()
{
try
{
var session_factory = NHibernateHelper.createSessionFactory();
using (var session = session_factory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var query = session.Linq<DomainModel.Model.Variabile>()
.OrderBy(v => v.ordine);
return query.ToList();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
Am i doing any mistakes? Could it be the one which provokes OutOfMemoryException? Best regards