我正在调用一个完整的服务,它反过来在 sql server 数据库中执行批量插入。当休息服务器和数据库服务器在同一台机器上时,一切正常,但在远程数据库服务器的情况下,出现以下异常。
System.InvalidOperationException: The transaction associated with the current
connection has completed but has not been disposed.
The transaction must be disposed before the connection can be used to
execute SQL statements.
我正在使用以下交易。
TransactionOptions tOptions = new TransactionOptions();
tOptions.IsolationLevel = IsolationLevel.ReadCommitted;
//This transaction is required here as it checks for all db operations.
using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, tOptions))
{
//DB operations....
transactionScope.Complete();
}