我正在将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