当我进行交易时,我得到:
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;
最佳答案
如Pete所述,这可能是连接池中的错误。无论如何,我注意到您的代码缺少MS要求的调用。从MSDN
尝试一下,看看它是否仍然发生。
关于c# - ado.net transaction.commit抛出semaphorefullexception,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4969793/