0
在我們的應用程序中,在保存操作過程中,我們將數據轉換爲近15個子表。發生某些錯誤時,表中的數據存在差異。所以我們決定使用TransactionScope。當我們使用它時,它給出錯誤說「事務已中止」,StackTrace顯示如下。事務在使用TransactionScope時中止
at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
at System.Transactions.CommittableTransaction.Commit()
at System.Transactions.TransactionScope.InternalDispose()
at System.Transactions.TransactionScope.Dispose()
我們的代碼看起來像
using (TransactionScope tScope = new TransactionScope())
{
dataManager.AddFood(food);
if (!ModelState.IsValid)
throw new ApplicationException("Model state is invalid");
if (beingCloned)
food.IsUserFood = false;
dataManager.Save();
if (!food.IsUserFood)
dataManager.GenerateSearchRecords(food.FoodID);
FoodManager foodManager = new FoodManager();
foodManager.CopyFoodToHistory(food);
if (beingCloned)
{
foodManager.CreateUserFoodCopyForClonedFood(food);
HttpPostedFileBase file = ControllerContext.HttpContext.Request.Files["Image"];
if (file != null && file.FileName.Length > 0)
foodManager.UpdateMediaCopyForClonedFood(food, true);
else
foodManager.UpdateMediaCopyForClonedFood(food);
}
tScope.Complete();
}
在此先感謝
是否拋出的異常有一個內部異常,如果是的話,它的消息? – hatchet
InnerException爲空 – jvm
是否必須對事務超時執行任何操作? – jvm