Scott you PM me. not sure if that was on purpose or not. anyway I'm
posting it here so others can follow.

what application doesn't have information that is constantly changing
and being refreshed. Nothing unique about there. The key is to define
the context boundary and treat this as your session boundary.
for web applications and messaging buses the boundary is easy. http
request or current thread.
desktop applications can be a bit trickier. some prefer a session per
form, while other like to use custom business contexts through the NH
Cptb(?) sample project.

are you disposing the session when you are finished with it? if not
then that's your problem. using the defaults provided by NH the code
should look something like this

open session
begin transaction
do work
if error rollkback transaction
otherwise commit transaction
close session

sample code might look like this
using(var session = factory.OpenSession())
using(var tx = session.BeginTransaction())
{
   try
   {
     do work
     tx.Commit();
   }
   catch
   {
     tx.Rollback();
     throw;
   }
}

in a web application it would look like this

class Global : HttpApplication
{
   public static ISessionFactory Factory {get; private set;}

   protected void Application_Start(object sender, EventArgs e)
   {
       Factory = new
Configuration().Configure().BuildSessionFactory();
   }

   protected void Application_End(object sender, EventArgs e)
   {
       Factory.Dispose();
   }

   public Global()
   {
      BeginRequest += (sender, e) =>
CurrentSessionContext.Bind(Factory.OpenSession());
      EndRequest += (sender, e) =>
CurrentSessionContext.Unbind(Factory).Dispose();
   }
}

using MVC you can manage the transaction using an action filter. With
webforms you can either use an extension method to encapsulate the
transaction, or use ATM on presenters.

"Hello Jason.

It's a situation where, as data is constantly changing, the page is
constantly refreshed, and the section "client code" from above is
routinely being executed.  Apparantly this causes semaphore
concurrency rpblems, and we're not sure why.  From what I've gathered,
it may be a matter of not closing connections properly.  As there is
no explicit connect/disconnect statement in the application, I'm
thinking there may be some parameter that nees to be in the web config
which I am not setting.  I'm specifying connection string, provider,
driver class, and dialect.  Anything else regarding the connection
that I'm missing?  I'm sort of greasping at straws here...

Also, there are a few areas of the app where a connection is declared
local to a method, performs a specific database operation (through a
stored proc) and fails to explicitly close the connection.  I don't
suppose that could cause a problem?  I would gather  that, as the
connection is declared locally, it would automatically close as the
method finishes execution, though I could be wrong..."

On Oct 4, 3:59 pm, Jason Meckley <[email protected]> wrote:
> how are you managing the session? are you trying to keep persisted
> entities in memory between requests (http session)?
> Usually problems with Nh arise for either improper mappings or poor
> session management.
>
> On Oct 4, 3:42 pm, scottl2001 <[email protected]> wrote:
>
> > On Oct 4, 2:06 pm, scottl2001 <[email protected]> wrote:
>
> > > Hello all.
>
> > > I'm getting a problem with semaphore timeouts which, as I gather are a
> > > result of connections not being closed properly.  I'm using Castle,
> > > NHibernate, and MS SQL Server  v 9.00.4035.00.
>
> > > Anybody experience this previously?  Details below.
>
> > > Thanks in advance!
>
> > > client code:
> > > -------------------------------------------------------------
> > > LtExpression statusLessThanShipped = new LtExpression("Status",
> > > Status.Shipped);
>
> > > IList<Run> runs = RunProvider.CustomQuery(new Order[]
> > > {Order.Asc("RunNumber") }, new ICriterion[]
> > > { statusLessThanShipped });
> > > ---------------------------------------------------------
>
> > > results in server error:
>
> > > ------------------------------------------------------------------
>
> > > Server Error in '/' Application.
> > > ________________________________________
> > > Adding the given count to the semaphore would cause it to exceed its
> > > maximum count.
> > > Description: An unhandled exception occurred during the execution of
> > > the current web request. Please review the stack trace for more
> > > information about the error and where it originated in the code.
>
> > > Exception Details: System.Threading.SemaphoreFullException: Adding the
> > > given count to the semaphore would cause it to exceed its maximum
> > > count.
>
> > > Source Error:
> > > An unhandled exception was generated during the execution of the
> > > current web request. Information regarding the origin and location of
> > > the exception can be identified using the exception stack trace below.
>
> > > Stack Trace:
>
> > > [SemaphoreFullException: Adding the given count to the semaphore would
> > > cause it to exceed its maximum count.]
> > >    System.Threading.Semaphore.Release(Int32 releaseCount) +5291316
>
> > > System.Data.ProviderBase.DbConnectionPool.PutNewObject(DbConnectionInternal
> > > obj) +57
>
> > > System.Data.ProviderBase.DbConnectionPool.DeactivateObject(DbConnectionInte­rnal
> > > obj) +230
>
> > > System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal
> > > obj, Object owningObject) +140
>
> > > System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection
> > > owningObject, DbConnectionFactory connectionFactory) +131
>
> > > System.Data.SqlClient.SqlInternalConnection.CloseConnection(DbConnection
> > > owningObject, DbConnectionFactory connectionFactory) +38
> > >    System.Data.SqlClient.SqlConnection.Close() +135
>
> > > NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection
> > > conn) +57
>
> > > [ADOException: Could not close System.Data.SqlClient.SqlConnection
> > > connection]
>
> > > NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection
> > > conn) +162
>
> > > NHibernate.Connection.DriverConnectionProvider.CloseConnection(IDbConnectio­n
> > > conn) +13
> > >    NHibernate.Impl.SessionFactoryImpl.CloseConnection(IDbConnection
> > > conn) +44
>
> > > [ADOException: cannot close connection]
> > >    NHibernate.Impl.SessionFactoryImpl.CloseConnection(IDbConnection
> > > conn) +96
> > >    NHibernate.Impl.ConnectionManager.CloseConnection() +25
> > >    NHibernate.Impl.ConnectionManager.AggressiveRelease() +59
> > >    NHibernate.Impl.ConnectionManager.AfterStatement() +116
> > >    NHibernate.Impl.BatcherImpl.CloseCommand(IDbCommand cmd) +141
> > >    NHibernate.Impl.BatcherImpl.CloseCommand(IDbCommand st, IDataReader
> > > reader) +125
> > >    NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
> > > QueryParameters queryParameters, Boolean returnProxies) +673
>
> > > NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImp­lementor
> > > session, QueryParameters queryParameters, Boolean returnProxies) +67
> > >    NHibernate.Loader.Loader.DoList(ISessionImplementor session,
> > > QueryParameters queryParameters) +51
> > >    NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor
> > > session, QueryParameters queryParameters) +18
> > >    NHibernate.Loader.Loader.List(ISessionImplementor session,
> > > QueryParameters queryParameters, ISet querySpaces, IType[]
> > > resultTypes) +81
> > >    NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList
> > > results) +331
> > >    NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) +39
> > >    NHibernate.Impl.CriteriaImpl.List() +15
> > >    Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType,
> > > Order[] orders, ICriterion[] criteria) +125
>
> > > [ActiveRecordException: Could not perform FindAll for Run]
> > >    Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType,
> > > Order[] orders, ICriterion[] criteria) +266
> > >    Castle.ActiveRecord.ActiveRecordBase`1.FindAll(Order[] orders,
> > > ICriterion[] criteria) +83
> > >    RunApplications.Data.Providers.BaseProvider`1.CustomQuery(Order[]
> > > order, ICriterion[] criteria) in C:\development2\In Progress
> > > \RunApplications\RunApplications.Data\Providers\BaseProvider.cs:139
> > >    RunApplications.Data.Providers.RunProvider.CustomQuery(Order[]
> > > order, ICriterion[] criteria) in C:\development2\In Progress
> > > \RunApplications\RunApplications.Data\Providers\RunProvider.cs:288
> > >    BusinessCenter.Web.Home.Page_Load(Object sender, EventArgs e) in C:
> > > \development2\In Progress\BSPBusinessCenter\BusinessCenter.Web
> > > \BusinessCenter.Web\Home.aspx.cs:23
> > >    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,
> > > Object o, Object t, EventArgs e) +14
> > >    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
> > > sender, EventArgs e) +35
> > >    System.Web.UI.Control.OnLoad(EventArgs e) +99
> > >    System.Web.UI.Control.LoadRecursive() +50
> > >    System.Web.UI.Page.ProcessRequestMain(Boolean
> > > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
> > > +627
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en.

Reply via email to