问题在昨天发的帖上,还未解决   http://topic.csdn.net/u/20110118/17/a0259cad-07a2-4ea2-b5d1-ce73e53208a5.html?seed=668975660&r=71314092#r_71314092  点击查看

解决方案 »

  1. 建议提交和回滚都要加上try,RollBack()放在catch里面
      

  2. public static int DoTransaction(string addUser,SqlParameter [] userPars,string addUserInfo,SqlParameter [] userInfoPars,string addForgetPass,SqlParameter [] fps)
     { 
                int flag = 0;
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = "连接字符串";
                SqlTransaction tran = Conn.BeginTransaction();
                SqlCommand comUsers = new SqlCommand();
                comUsers.Connection = Conn;
                comUsers.Transaction = tran;
                comUsers.CommandType = CommandType.StoredProcedure;
                try
                {
                    
                    comUsers.Parameters.AddRange(userPars);
                    comUsers.ExecuteNonQuery();                comUsers.Parameters.AddRange(userInfoPars);
                    comUsers.Transaction = tran;
                    comUsers.ExecuteNonQuery();
                    comUsers.Parameters.AddRange(fps);
                    comUsers.Transaction = tran;
                    comUsers.ExecuteNonQuery();
                    tran.Commit();
                    flag= 1;
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                }
                finally
                {                tran.Dispose();
                }
                return flag;
     }
      

  3.  同学,您的return阻止了Rollback
    return的优先级高
      

类似问题 »