Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SemaphoreFullException when checking user role via ASP.NET membership

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

like image 328
Stark Raving Avatar asked Jul 29 '11 17:07

Stark Raving


4 Answers

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.

like image 172
hagensoft Avatar answered Nov 16 '22 13:11

hagensoft


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)

like image 28
Lukas Avatar answered Nov 16 '22 15:11

Lukas


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 ...

like image 12
O'Rooney Avatar answered Nov 16 '22 13:11

O'Rooney


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.

like image 6
Codeman Avatar answered Nov 16 '22 13:11

Codeman