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

Masoud
  • 8,020
  • 12
  • 62
  • 123
Stark Raving
  • 400
  • 1
  • 3
  • 7

8 Answers8

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.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
hagensoft
  • 1,497
  • 13
  • 13
  • 18
    Disabling pooling has huge performance implications. This answer suggest extremely bad advice. – usr Oct 03 '13 at 19:00
  • 1
    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. http://forums.asp.net/t/1710783.aspx – hagensoft Oct 04 '13 at 16:03
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 ...

O'Rooney
  • 2,878
  • 2
  • 27
  • 41
  • 24
    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. – O'Rooney Sep 01 '11 at 04:49
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)

Lukas
  • 2,885
  • 2
  • 29
  • 31
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.

Codeman
  • 12,157
  • 10
  • 53
  • 91
  • 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. – Lukas Feb 06 '13 at 17:55
5

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

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Mike
  • 71
  • 1
  • 1
5

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

CailinP
  • 224
  • 4
  • 15
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.

Mike G
  • 4,232
  • 9
  • 40
  • 66
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.

MikeD
  • 923
  • 4
  • 12
  • 24