SemaphoreFullException when checking user role via ASP.NET membership
Asked Answered
V

8

38

I have a page that checks that a user is in a particular role before performing some task, and have had no problem with functionality and have made no obvious related changes to the code in question. The site is on my development machine (Windows Vista) running IIS 7.0 and the database is MS SQL 2005 on a separate server. Suddenly, all calls to the User.IsInRole are resulting in

System.Threading.SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum count.

I'm sure restarting IIS will "resolve" the issue, but I'd like to understand what caused it so I can ensure it doesn't happen on my production site.

The top of the stack trace is:

[SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum count.] System.Threading.Semaphore.Release(Int32 releaseCount) +6065293 System.Data.ProviderBase.DbConnectionPool.PutNewObject(DbConnectionInternal obj) +57 System.Data.ProviderBase.DbConnectionPool.DeactivateObject(DbConnectionInternal obj) +338 System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj, Object owningObject) +163 System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory) +117 System.Data.SqlClient.SqlInternalConnection.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory) +37 System.Data.SqlClient.SqlConnection.Close() +158 System.Web.DataAccess.SqlConnectionHolder.Close() +25 System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) +847 System.Web.Security.RolePrincipal.IsInRole(String role) +182

Vulnerable answered 29/7, 2011 at 17:15 Comment(0)
B
24

This issue was fixed by restarting ASP.NET Development Server on windows taskbar.

Or permanently by adding 'Pooling=False;' to the connection string should solve the issue.

Bathyscaphe answered 9/10, 2012 at 23:19 Comment(2)
Disabling pooling has huge performance implications. This answer suggest extremely bad advice.Couching
Thank you. I agree with the lack of performance, but performance was not the question asked. It was about fixing the bug/issue and BTW going from not being able to run the application to taking a few miliseconds to connect is a great increment in performance. I do recommend to investigate the root cause and remove the pooling=false if that option was necessary to be used at all. forums.asp.net/t/1710783.aspxBathyscaphe
U
12

I'm getting it occasionally too.

I believe that in my case, it was occurring because I was stopping the debugger during page execution, so perhaps the db connection pool got messed up.

There is a long thread discussing this here: http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/b5b7a179-3737-4380-b6cf-843f3e71b317/

with various users reporting the same thing. There is no definite conclusion, Microsoft seems to feel our applications are closing a handle they should not. But in our app at least there are no CloseHandle calls.

If it was a genuine bug in db connection pooling I would have thought it would be found long ago, as this is the stuff that runs every asp.net website ...

Unquestionable answered 30/8, 2011 at 22:25 Comment(1)
I believe that in my case, it might be occurring because I was stopping the debugger during page execution, so perhaps the db connection pool got messed up.Vincentvincenta
L
11

I know it's been posted, but here is how I got it, and what resolved it.

What I did Put a break point near the code segment that makes an SQL call.

What Solved It Restarting ASP.NET Development Server in windows system tray (next to your clock in bottom-right corner)

Libenson answered 6/2, 2013 at 17:57 Comment(0)
Q
6

This happened to me when I inserted a break point on a line that was making a SQL call.

Placing the breakpoint at a later point (not at a SQL call) solved the problem for me.

Quorum answered 29/6, 2012 at 20:29 Comment(1)
How about that? I'm not sure why but that is EXACTLY what I did before I saw this error. I solved it by closing the ASP.NET Development Server - Port #### in my system tray.Libenson
Z
5

Restarting ASP.NET Cassini on windows taskbar fixed this for me!

Zabrine answered 25/10, 2012 at 18:44 Comment(0)
P
5

Restarting Visual Studio solved it for me. I had stopped the debugger during a page load.

Purificator answered 17/6, 2014 at 18:35 Comment(2)
In addition, I restarted IIS as well.Rubirubia
I tried recycling the app pool on the server and that didn't clear it up. But Restarting Visual Studio (as you suggested) did.Overlie
R
1

I started getting this error roughly every other build this morning. Restarting the Development LocalHost server started becoming really tedious, so I started digging. Long story short, there was a SqlConnection/SqlCommand pair that was never disposed over, refactoring that code stopped the Exception.

Rhodos answered 6/9, 2013 at 14:57 Comment(0)
H
0

I got the same thing when running on IIS locally. Seems to be due to stopping debugger when starting up the site. Running 'iisreset' fixed it.

Hesse answered 16/1, 2013 at 5:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.