2013-12-13 96 views
2

我想通過實體v.4.0.30319圍繞我對存儲過程的調用包裝一個TransactionScope。我一直遇到以下異常:無法升級IsolationLevel快照的交易

無法升級IsolationLevel Snapshot的事務。

我該如何解決這個問題?

底層存儲過程基本上是一個大表插入語句。

我的代碼如下:

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, GetTransactionOptions())) 
{ 
    int? status; 
    status = GetStatusIDFromEnum(newMatterCredential); 

    using (MatterCredentialsEntities db = new MatterCredentialsEntities()) 
    { 
     DateTime? objDateAnnounced = GenerateNullForDateTime(newMatterCredential.DateAnnounced); 
     DateTime? objDateClosed = GenerateNullForDateTime(newMatterCredential.DateClosed); 
     DateTime? objDateFinancialClosed = GenerateNullForDateTime(newMatterCredential.DateFinancialClosed); 
     db.prcCreateCredential(Common.GetUserProfID(), newMatterCredential.MatterID, status, newMatterCredential.DescriptionSummary, newMatterCredential.DescriptionDetailed, newMatterCredential.BusinessEntitySectorID, newMatterCredential.BusinessEntityRoleID, newMatterCredential.UNGeographyID, newMatterCredential.ProjectName, newMatterCredential.ClientIndustryId, newMatterCredential.TransactionValue, newMatterCredential.TransactionCurrencyID, newMatterCredential.OtherParties, newMatterCredential.LegalAdvisers, newMatterCredential.DateAnnounced, newMatterCredential.DateClosed, newMatterCredential.DateFinancialClosed, newMatterCredential.Award, newMatterCredential.NotifyPartner, newMatterCredential.Notes); 
    } 

    scope.Complete(); 
} 

public static TransactionOptions GetTransactionOptions() 
{ 
    TransactionOptions tranOpt = new TransactionOptions(); 
    tranOpt.IsolationLevel = IsolationLevel.Snapshot; 
    return tranOpt; 
} 

回答

2

MSDN說,你不能促進與快照隔離事務。

MSDN - IsolationLevel Enumeration

快照 - 易失性的數據可以被讀取。在事務修改數據之前,它會驗證在最初讀取數據後另一個事務是否更改了數據。如果數據已更新,則會引發錯誤。這允許事務達到先前承諾的數據值。 當您嘗試推廣,將其與該隔離級別一個事務,則會引發InvalidOperationException並顯示錯誤消息:

交易具有的IsolationLevel快照不能促進

有些東西必須改變自開始交易以來的數據,如果這是它參與的較大交易的一部分

我建議將交易更改爲可序列化。

public static TransactionOptions GetTransactionOptions() 
{ 
    TransactionOptions tranOpt = new TransactionOptions(); 
    tranOpt.IsolationLevel = IsolationLevel.Serializable; 
    return tranOpt; 
} 

編輯:請參閱下文,確保您有MSDTC運行,因爲它想創建一個分佈式事務。

+0

更改爲可序列化返回以下例外: 事務管理器已禁用其對遠程/網絡事務的支持。 –

+1

聽起來像是MSDTC配置問題。您需要:
1.通過TCP/IP啓用NetBIOS 2.通過組件服務啓用MSDTC 這是所有MSDTC的最佳鏈接,[鏈接](http://msdn.microsoft.com/en-us /library/aa561924.aspx) – jcrawfor74