我们有一个方便的委托功能,它允许我们将多个调用包含在同一个事务中。
protected delegate object DatabaseFunctions();
protected object ExecuteInTransaction(DatabaseFunctions databaseFunctions)
{
TransactionScope scope = null;
if(!TransactionScope.IsInTransaction)
scope = new TransactionScope();
try
{
Object obj = databaseFunctions();
if (scope != null)
scope.Complete();
return obj;
}
......
我们在自托管WCF端点,WebAPI基础库内部和多线程Windows服务中使用此方法。
我们正在经历以下错误的增加。这曾经发生过,现在确实发生了(每周3~4次),它被多个线程抛出。我有一个理论认为这不是在自托管的WCF服务中发生的......也许是因为那里的调用具有PER CALL集的实例资源。但尚未100%确认。
1)这里究竟出现了什么问题......提供商是否很难打开与SQL Server的连接,或者它实际上很难开始交易?这真的是暂停吗?
2)这可能与MSDTC有关吗?通常我会看到MSDTC错误,如果这实际上是问题...我没有看到任何东西,但无法判断堆栈跟踪是否表明正在使用MSDTC。
3)在问题出现之前,我们对系统的“负载”肯定已经上升了。
ExecuteInTransaction中的错误IBatisNet.DataMapper.Exceptions.DataMapperException:无法打开与“Microsoft SQL Server,框架.NET V4.0中的提供程序V4.0.0.0”的连接。 ---> System.Transactions.TransactionException:该操作对事务的状态无效。 ---> System.TimeoutException:事务超时
---内部异常堆栈跟踪结束---
在System.Transactions.TransactionState.EnlistPromotableSinglePhase(InternalTransaction tx,IPromotableSinglePhaseNotification promotableSinglePhaseNotification,Transaction atomicTransaction)
在System.Transactions.Transaction.EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification promotableSinglePhaseNotification)
在System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
在System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
在System.Data.SqlClient.SqlInternalConnectionTds.Activate(事务处理事务)
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
在System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject,DbConnectionInternal obj,Transaction transaction)
在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal& connection)
在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource 1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1重试,DbConnectionOptions userOptions)
在System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
1重试)
在System.Data.SqlClient.SqlConnection.Open()
at IBatisNet.DataMapper.SqlMapSession.OpenConnection(String connectionString)
---内部异常堆栈跟踪结束---
at IBatisNet.DataMapper.SqlMapSession.OpenConnection(String connectionString)
在IBatisNet.DataMapper.SqlMapSession.OpenConnection()
在IBatisNet.DataMapper.Commands.DbCommandDecorator.System.Data.IDbCommand.ExecuteScalar()
at IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteInsert(ISqlMapSession session,Object parameterObject)
在IBatisNet.DataMapper.SqlMapper.Insert(String statementName,Object parameterObject)
感谢您的帮助!!