I've been having this SemaphoreFullException for quiet some time.
我一直在安静这个SemaphoreFullException。
To summarize.. I have hosted an application on IIS 7.5 with ASP.NET v4.0 framework Application Pool (integrated). I am using windows authentication to authenticate my users through domain (isinrole).
总结一下..我在IIS 7.5上托管了一个带有ASP.NET v4.0框架应用程序池(集成)的应用程序。我正在使用Windows身份验证通过域(isinrole)验证我的用户。
I've seen all other threads on this topic, where it is suggested to set Pooling = False. I do not want to do that and I would like to keep on using pooling because of the performance benefits.
我已经看过这个主题的所有其他主题,建议设置Pooling = False。我不想这样做,因为性能优势,我想继续使用池。
I am using Entity Framework 6 to query the database and I am not "disposing" the dbcontext anywhere in user code. It looks like the issue is in the DbConnectionPool code.
我正在使用Entity Framework 6来查询数据库,我没有在用户代码中的任何地方“处理”dbcontext。看起来这个问题出现在DbConnectionPool代码中。
The error occurs randomly at any given moment of time. It doesn't matter if the application is being used or not. Sometimes, due to this issue - I have to restart IIS because new users stop getting authenticated.
错误在任何给定的时刻随机发生。无论是否使用该应用程序都无关紧要。有时,由于此问题 - 我必须重新启动IIS,因为新用户停止进行身份验证。
What I've tried so far:
到目前为止我尝试了什么:
- Check whether a DB transaction object is being disposed.
- 检查是否正在处理数据库事务对象。
- Check whether a DBContext (ctx) is being disposed prematurely.
- 检查DBContext(ctx)是否过早处理。
- Check application build (32/62 bit). In this case - I build the application in ANY CPU mode and my server is 64 bit.
- 检查应用程序构建(32/62位)。在这种情况下 - 我在任何CPU模式下构建应用程序,我的服务器是64位。
Note: In my application, I've mostly used linq-to-EF objects to query the DB.
注意:在我的应用程序中,我主要使用linq-to-EF对象来查询数据库。
Exception: System.Threading.SemaphoreFullException
Message: Adding the specified count to the semaphore would cause it to exceed its maximum count.
StackTrace: at System.Threading.Semaphore.Release(Int32 releaseCount)
at System.Data.ProviderBase.DbConnectionPool.CleanupCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
Any help in this regard will be greatly appreciated.
在这方面的任何帮助将不胜感激。
3 个解决方案
#1
4
I think that this may be a solution to the problem: http://www.davepaquette.com/archive/2013/03/27/managing-entity-framework-dbcontext-lifetime-in-asp-net-mvc.aspx - as you can see there, it is essential to take care for disposal of the DbContext when it´s lifetime is over.
我认为这可能是解决问题的方法:http://www.davepaquette.com/archive/2013/03/27/managing-entity-framework-dbcontext-lifetime-in-asp-net-mvc.aspx - 正如你在那里看到的那样,在生命周期结束时必须小心处理DbContext。
Remember, Db connections end up in unmanaged db handling code, so the problem is unless garbage collection disposes the context it stays sleeping in the main memory, thereby also blocking a connection from the connection pool. So sooner or later, under the right conditions, you empty the connection pool and get your exception.
请记住,Db连接最终会出现在非托管数据库处理代码中,因此问题是除非垃圾收集处理它在主内存中保持睡眠的上下文,从而也阻止了连接池的连接。所以迟早,在适当的条件下,您清空连接池并获得异常。
#2
8
In my case, the problem was that I stopped the application while debugging. The application was making a lot of async callings.
就我而言,问题是我在调试时停止了应用程序。该应用程序正在进行大量的异步调用。
So I reset my IIS server: iisreset
via Command Prompt or PowerShell, and it worked.
所以我重置我的IIS服务器:iisreset通过命令提示符或PowerShell,它工作。
#3
1
I had the same problem and was because I was doing .Dispose();
before closing the connection this is how I solved it:
我有同样的问题,因为我在做.Dispose();在关闭连接之前,我就是这样解决的:
I had two instances of .Dispose();
- one in a SqlDataAdapter, the other in one SqlCommand and after that was closing the connection and getting the error. Just removed the .Dispose();
from my SqlCommand and my SqlDataAdapter, and no more error! I hope this helps somehow.
我有两个.Dispose()实例; - 一个在SqlDataAdapter中,另一个在一个SqlCommand中,然后关闭连接并得到错误。刚删除.Dispose();从我的SqlCommand和我的SqlDataAdapter,没有更多的错误!我希望这会有所帮助。
#1
4
I think that this may be a solution to the problem: http://www.davepaquette.com/archive/2013/03/27/managing-entity-framework-dbcontext-lifetime-in-asp-net-mvc.aspx - as you can see there, it is essential to take care for disposal of the DbContext when it´s lifetime is over.
我认为这可能是解决问题的方法:http://www.davepaquette.com/archive/2013/03/27/managing-entity-framework-dbcontext-lifetime-in-asp-net-mvc.aspx - 正如你在那里看到的那样,在生命周期结束时必须小心处理DbContext。
Remember, Db connections end up in unmanaged db handling code, so the problem is unless garbage collection disposes the context it stays sleeping in the main memory, thereby also blocking a connection from the connection pool. So sooner or later, under the right conditions, you empty the connection pool and get your exception.
请记住,Db连接最终会出现在非托管数据库处理代码中,因此问题是除非垃圾收集处理它在主内存中保持睡眠的上下文,从而也阻止了连接池的连接。所以迟早,在适当的条件下,您清空连接池并获得异常。
#2
8
In my case, the problem was that I stopped the application while debugging. The application was making a lot of async callings.
就我而言,问题是我在调试时停止了应用程序。该应用程序正在进行大量的异步调用。
So I reset my IIS server: iisreset
via Command Prompt or PowerShell, and it worked.
所以我重置我的IIS服务器:iisreset通过命令提示符或PowerShell,它工作。
#3
1
I had the same problem and was because I was doing .Dispose();
before closing the connection this is how I solved it:
我有同样的问题,因为我在做.Dispose();在关闭连接之前,我就是这样解决的:
I had two instances of .Dispose();
- one in a SqlDataAdapter, the other in one SqlCommand and after that was closing the connection and getting the error. Just removed the .Dispose();
from my SqlCommand and my SqlDataAdapter, and no more error! I hope this helps somehow.
我有两个.Dispose()实例; - 一个在SqlDataAdapter中,另一个在一个SqlCommand中,然后关闭连接并得到错误。刚删除.Dispose();从我的SqlCommand和我的SqlDataAdapter,没有更多的错误!我希望这会有所帮助。