日期:2014-05-18  浏览次数:21686 次

报错:ROLLBACK TRANSACTION 请求没有对应 BEGIN TRANSACTION
C# code

        private static void Prepare(SqlConnection con, SqlCommand cmd, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
        {
            con.ConnectionString = ConnectionString;
            cmd.Connection = con;
            cmd.CommandType = cmdType;
            cmd.CommandText = cmdText;
            if (cmdParms != null)
            {
                foreach (SqlParameter parm in cmdParms)
                    cmd.Parameters.Add(parm);
            }

            con.Open();
        }

 public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
        {
            using (SqlConnection con = new SqlConnection())
            {
                int iResult = -1;
                SqlCommand cmd = new SqlCommand();
                Prepare(con, cmd, cmdType, cmdText, cmdParms);
                SqlTransaction tran = con.BeginTransaction();

                try
                {
                    iResult = cmd.ExecuteNonQuery();
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }

                return iResult;
            }//end using
        }



数据库是SQL Server 2000,368条Insert语句,每条语句12个字段。
之前插入都是正常的,今天突然就报错了。

------解决方案--------------------
没改过代码的话,就是数据库问题。