具有成员资格和角色的TransactionScope在同一块中调用(仅使用一个连接?)

| 我在同一事务范围内调用了Membership API和Roles API。我已经读到,打开多个连接会导致升级,需要启用分布式事务,所以我正在寻找一种打开一个连接并与之共享的方法:成员资格,角色,我自己的电话。 这是导致不必要的升级的工作代码:
public static void InsertUser(string userName, string email, string roleName, int contactId, string comment)
      {
         /*
          * Exceptions thrown here are caught in the DetailView\'s event handler and piped to the UI.
          */

         using(var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
         {
            string password = Membership.GeneratePassword(Membership.MinRequiredPasswordLength, Membership.MinRequiredNonAlphanumericCharacters);
            const string passwordQuestion = \"Should you change your password question?\";
            const string passwordAnswer = \"yes\";
            MembershipCreateStatus status;
            MembershipUser user = Membership.CreateUser(userName, password, email, passwordQuestion, passwordAnswer, true, out status);

            if(user == null)
            {
               throw new Exception(GetErrorMessage(status));
            }

            // Flesh out new user
            user.Comment = comment;
            Membership.UpdateUser(user);

            // Give user a role
            Roles.AddUserToRole(user.UserName, roleName);

            // Create bridge table record
            Guid userId = (Guid)ExceptionUtils.ThrowIfDefaultValue(user.ProviderUserKey, \"ProviderUserkey is null!\");
            insertIntoAspnet_Users_To_Contact(userId, contactId);

            // Send welcome email
            EmailUtils.SendWelcomeEmailFromAdmin(userName, email, password, passwordQuestion, passwordAnswer, roleName);

            transactionScope.Complete();
         }
      }
谢谢     
已邀请:
        如果您具有SQL2008或更高版本,则它可以处理多个连接上的事务,而无需升级为MSDTC。要求对所有连接使用完全相同的连接字符串。 如果您使用的是较低版本的SQL Server,我认为您松了手。几个月前,我对此进行了调查,但发现没有办法进行处理,因此我最终跳过了事务并改为执行自己的错误处理。客户使用了SQL2005,因此无法升级。     
        您指定了“ 1”,这意味着即使您已经有合适的环境代码,每次传入该代码段时也要进行一次新事务。 只是这样做:
using(var transactionScope = new TransactionScope())
    

要回复问题请先登录注册