开发者

SemaphoreFullException when checking user role via ASP.NET membership

开发者 https://www.devze.com 2023-03-24 01:29 出处:网络
I have a page that checks that a user is in a particular role before performing some task, and have had no problem with functionalit开发者_JAVA技巧y and have made no obvious related changes to the cod

I have a page that checks that a user is in a particular role before performing some task, and have had no problem with functionalit开发者_JAVA技巧y 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


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.


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


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)


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.


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


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消