ado.net transaction.commit 抛出 semaphorefullexception
当我提交交易时,我得到:
System.Threading.SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum count.
at System.Threading.Semaphore.Release(Int32 releaseCount)
at System.Data.ProviderBase.DbConnectionPool.PutNewObject(DbConnectionInternal obj)
at System.Data.ProviderBase.DbConnectionPool.DeactivateObject(DbConnectionInternal obj)
at System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj, Object owningObject)
at System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Close()
at System.Data.SqlClient.SqlConnection.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
// rest of my stack trace here
这是什么意思?我是否没有在某处正确关闭连接并且已填满池?如果是这样,我如何在 SQL Server 2008 R2 中检查这一点?
这是我的代码(尽管这可能不是导致连接泄漏的代码)
using (var connection = connectionFactory.GetConnection())
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
try
{
using (var command = connection.CreateCommand())
{
command.Connection = connection;
command.Transaction = transaction;
command.CommandText = "some sql"
data = (string) command.ExecuteScalar();
transaction.Commit();
}
}
catch
{
try
{
transaction.Rollback();
}
catch
{
}
throw;
}
}
}
return data;
When I commit my transaction, i'm getting:
System.Threading.SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum count.
at System.Threading.Semaphore.Release(Int32 releaseCount)
at System.Data.ProviderBase.DbConnectionPool.PutNewObject(DbConnectionInternal obj)
at System.Data.ProviderBase.DbConnectionPool.DeactivateObject(DbConnectionInternal obj)
at System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj, Object owningObject)
at System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Close()
at System.Data.SqlClient.SqlConnection.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
// rest of my stack trace here
What does this mean? Am I not closing a connection properly somewhere and have filled the pool up? If so, how do I check this in SQL Server 2008 R2?
here's my code (although this may not be the code guilty of causing the connection leak)
using (var connection = connectionFactory.GetConnection())
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
try
{
using (var command = connection.CreateCommand())
{
command.Connection = connection;
command.Transaction = transaction;
command.CommandText = "some sql"
data = (string) command.ExecuteScalar();
transaction.Commit();
}
}
catch
{
try
{
transaction.Rollback();
}
catch
{
}
throw;
}
}
}
return data;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如皮特提到的,这可能是连接池中的一个错误。无论如何,我注意到您的代码缺少 MS 所说需要的调用。来自 MSDN
尝试一下,看看它是否仍然会发生。
As Pete mentioned, this might be a bug in connection pooling. In any case, I noticed your code is missing a call that MS says is required. From MSDN
Give that a try and see if it still happens.