通过 ASP.NET 成员身份检查用户角色时出现 SemaphoreFullException
我有一个页面,用于在执行某些任务之前检查用户是否处于特定角色,并且功能没有问题,并且没有对相关代码进行明显的相关更改。该站点位于我的运行 IIS 7.0 的开发计算机 (Windows Vista) 上,数据库是位于单独服务器上的 MS SQL 2005。突然间,对 User.IsInRole
的所有调用都会导致
System.Threading.SemaphoreFullException:将指定的计数添加到信号量将导致其超过其最大计数。
我确信重新启动 IIS 将“解决”该问题,但我想了解导致该问题的原因,以便确保它不会在我的生产站点上发生。
堆栈跟踪的顶部是:
[SemaphoreFullException:将指定的计数添加到信号量将导致其超过其最大计数。] System.Threading.Semaphore.Release(Int32releaseCount)+6065293 System.Data.ProviderBase.DbConnectionPool.PutNewObject(DbConnectionInternal obj) +57 System.Data.ProviderBase.DbConnectionPool.DeactivateObject(DbConnectionInternal obj)+338 System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj,对象 owningObject)+163 System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject,DbConnectionFactory 连接工厂)+117 System.Data.SqlClient.SqlInternalConnection.CloseConnection(DbConnection owningObject,DbConnectionFactory 连接工厂)+37 System.Data.SqlClient.SqlConnection.Close() +158 System.Web.DataAccess.SqlConnectionHolder.Close() +25 System.Web.Security.SqlRoleProvider.GetRolesForUser(字符串用户名)+847 System.Web.Security.RolePrincipal.IsInRole(字符串角色)+182
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
通过在 Windows 任务栏上重新启动 ASP.NET Development Server 已修复此问题。
或者永久添加“Pooling=False;”连接字符串应该可以解决问题。
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.
我也偶尔会遇到。
我相信就我而言,发生这种情况是因为我在页面执行期间停止调试器,所以数据库连接池可能被搞乱了。
这里有一个很长的话题讨论这个问题:
http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/b5b7a179-3737-4380-b6cf-843f3e71b317/
不同的用户报告了同样的事情。
没有明确的结论,微软似乎觉得我们的应用程序正在关闭一个他们不应该关闭的句柄。但在我们的应用程序中至少没有 CloseHandle 调用。
如果这是数据库连接池中的一个真正的错误,我会认为它很久以前就会被发现,因为这是运行每个 asp.net 网站的东西......
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 ...
我知道它已发布,但这是我得到它的方式以及解决方法。
我做了什么
在进行 SQL 调用的代码段附近放置一个断点。
什么解决了这个问题
在 Windows 系统托盘中重新启动 ASP.NET 开发服务器(右下角时钟旁边)
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)
当我在进行 SQL 调用的行上插入断点时,就发生了这种情况。
将断点放在稍后的位置(而不是在 SQL 调用处)解决了我的问题。
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.
在 Windows 任务栏上重新启动 ASP.NET Cassini 为我解决了这个问题!
Restarting ASP.NET Cassini on windows taskbar fixed this for me!
重新启动 Visual Studio 为我解决了这个问题。我在页面加载期间停止了调试器。
Restarting Visual Studio solved it for me. I had stopped the debugger during a page load.
今天早上我几乎每隔一个构建就开始遇到这个错误。重新启动开发 LocalHost 服务器开始变得非常乏味,所以我开始挖掘。长话短说,有一个
SqlConnection
/SqlCommand
对从未被释放,重构该代码停止了异常。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.我在本地 IIS 上运行时也遇到同样的情况。似乎是由于启动站点时停止调试器。运行“iisreset”修复了它。
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.