Semaphore exception - Adding the specified count to the semaphore would cause it to exceed its maximum count

徘徊边缘 提交于 2019-12-03 02:56:24

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.

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.

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.

EDIT: Look at the @aaroncatlin comment for IIS Express

JCO9

I had the same problem and was because I was doing .Dispose(); before closing the connection this is how I solved it:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!