问题描述
我遇到错误:与当前连接关联的事务已完成,但尚未处理。在Log.WriteEntry($“尝试为事务{transaction.TransactionLogId}创建发票时发生错误:{ex.Message}”);运行代码时的声明。有人可以帮忙吗?
public virtual GroupCreationResult CreateGroups(IEnumerable<TransactionDetail> transactions)
{
var transactionDetails = transactions as TransactionDetail[] ?? transactions.ToArray();
var successes = new List<int>(transactionDetails.Length);
var errors = new List<TransactionError>();
foreach (var transaction in transactionDetails)
{
using (var scope = new TransactionScope(TransactionScopeOption.required,new Transactionoptions { IsolationLevel = IsolationLevel.ReadCommitted,Timeout = new TimeSpan(0,2,0) }))
{
try
{
foreach (var service in _invoiceCreationServices)
{
try
{
service.CreateInvoice(transaction);
}
catch (Exception ex)
{
Log.WriteEntry($"Error occurred while trying to create invoice for transaction {transaction.TransactionLogId} : {ex.Message}");
if (!(ex.ToString().Contains("Violation of PRIMARY KEY constraint 'PK_APInvGrp'.") || ex.ToString().Contains("Violation of PRIMARY KEY constraint .")))
{
Log.WriteEntry($"error occured while adding the transaction {transaction.TransactionLogId} - {ex.ToString()}");
errors.Add(new TransactionError(transaction.TransactionLogId,ex.ToString()));
scope.Complete();
break;
}
}
}
Log.WriteEntry($"successfully added the transaction {transaction.TransactionLogId}");
successes.Add(transaction.TransactionLogId);
scope.Complete();
}
catch (Exception exception)
{
Log.WriteEntry($"error1 occured while adding the transaction {transaction.TransactionLogId} - {exception.ToString()}");
//errors.Add(new TransactionError(transaction.TransactionLogId,exception.ToString()));
}
}
}
return BuildGroupCreationResult(successes,errors);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)