我正在將asp.net成員資格升級爲MVC4中新的簡單成員提供程序。這是一個Azure/Sql Azure應用程序,它可以在本地主機上正常運行,但在部署時會失敗。我有代碼的交易如下:Simplerole提供程序導致事務處理範圍內的遠程事務
TransactionOptions toptions = new TransactionOptions();
toptions.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, toptions))
{
try
{
... do a bunch of database stuff in a single dbContext ...
var roleprov = (SimpleRoleProvider)Roles.Provider;
string[] roles = roleprov.GetRolesForUser(Username);
// above line fails with The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024)
}
}
我使用this technique填充角色類。堆棧跟蹤似乎表明它確實試圖啓動一個子事務來完成該調用。 simplemembership表在不同的數據庫中。如何從單獨事務的上下文中的角色提供者獲取角色信息?
最後,我找到了一種方法將角色從事務處理中取出。這有點尷尬,但它工作。我在這裏發現了一篇關於該問題的文章(http://social.technet.microsoft.com/wiki/contents/articles/handling-transactions-in-sql-azure.aspx) – AldenG
@AldenG。是的,所以(「_當你有多個連接到不同的數據庫._)證實了我上面所說的。最後是否使用'SqlTransaction'而不是?我留下了該選項,因爲我認爲你需要堅持使用Roles和DbContext以減少與數據庫的耦合 –
我使用SqlTransaction玩了一個小時,並找不到一種方式使它與實體框架很好地協作,將它從事務處理器中拉出來最終獲得了最簡單的解決方案,並且使用了一對擴展方法要訪問角色,代碼結束了足夠乾淨。感謝您的幫助。 – AldenG