c#LinqToSql - TransactionIsInDoubt exception

时间:2017-05-31 07:10:49

标签: c# .net linq-to-sql

我有这个简单的webapi方法,使用 linqtosql 来执行一些存储 过程:

[Authorize]
[Route("save")]
public IHttpActionResult api_Offert_SAVE(reqOffertSave req)
{

    try {

        using (var transaction = new TransactionScope())
        {
            var db2 = new OffertAppContext();

            db2.Offert_CLEAR(req.idOffert);

            db2.Offert_UPD_Header(req.idOffert, null, req.Title, req.Category, req.DatePickUp, req.DateDelivery, req.idDeliveryType, req.idPaymentType, req.PaymentDetail, req.ShippingDetail,req.idOffertSequel, req.Note);

            foreach (var r in req.Regions)
            {
                int? _idOffertRegion = null;
                db2.Offert_ADD_Region(req.idUserLastEdit, req.idOffert, r.Region,ref _idOffertRegion);

                var products = req.Products.Where(x => x.idOffertRegion == r.idOffertRegion).ToList();
                foreach (var p in products)
                {
                    int? x = null;
                    if(p.idProduct == 0)
                        db2.Offert_ADD_ProductDummy_FULL(req.idUserLastEdit, req.idOffert, _idOffertRegion, p.Product, p.idProductService, p.Qty, p.idUnitPrice, p.PriceCustomer, p.SeatsCustomer,p.Discount, ref x);                            
                    else
                        db2.Offert_ADD_Product_FULL(req.idUserLastEdit, req.idOffert, _idOffertRegion, p.idProduct, p.idProductService, p.Qty, p.PriceCustomer, p.SeatsCustomer,p.Discount, ref x);

                }

            }
            db2.Offert_CALCULATE_Totals(req.idOffert);
            transaction.Complete();
        }


        return Ok(1);
    }
    catch (Exception e)
    {
        return BadRequest(e.Message);
    }
}

Al工作正常,直到昨天我更新了dbml文件......

我想知道为什么会出现交易问题...应用程序尚未投入生产,此时我是唯一访问数据库的人...

在这种方法中我只调用存储过程,为什么我得到" 交易有疑问"例外?

我的机器上启用了MSDTC。

根据建议,我查看了这个问题:

Reason for System.Transactions.TransactionInDoubtException

但是,我的情况完全不同于平面......

注意:

经过一些检查后,我发现如果我删除这一行:

db.Offert_CALCULATE_Totals(req.idOffert);

错误停止......

感谢支持

0 个答案:

没有答案