Esempio n. 1
0
        /// <summary>
        /// 运行指定的存储过程
        /// </summary>
        /// <param name="procName">存储过程名</param>
        /// <param name="prams">对于存储过程有输入参数的数组</param>
        /// <returns></returns>
        public bool RunProcLob(
            string procName,
            SqlParameter[] prams,
            ref int ErrorID,
            ref string ErrorMsg)
        {
            DataSet Ds    = new DataSet();
            bool    blret = false;

            try
            {
                ///建立事物处理
                Sqltx = SqlCn.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

                SqlCommand cmd = CreateCommand(procName, prams, true);
                cmd.Prepare();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(Ds);
                blret = true;

                da.Dispose();
                cmd.Dispose();
                Sqltx.Commit();
            }
            catch (SqlException sqlex)
            {
                // Specific catch for deadlock
                if (sqlex.Number != 1205)
                {
                    if (Sqltx != null)
                    {
                        //回滚事物
                        Sqltx.Rollback();
                    }
                }
                ErrorMsg = DBErrorMessageHelper.GetErrorDesc(sqlex.Number.ToString(), sqlex.Message);
                ErrorID  = sqlex.Number;
                if (ErrorMsg == "")
                {
                    throw (sqlex);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (Sqltx != null)
                {
                    //回滚事物
                    Sqltx.Rollback();
                }
                throw (ex);
            }
            return(blret);
        }
Esempio n. 2
0
        public bool RunProcsRet(
            string[] spName,
            ArrayList al,
            ref int ErrorID,
            ref string ErrorMsg)
        {
            bool blret = false;

            try
            {
                ///建立事物处理
                Sqltx = SqlCn.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

                for (int i = 0; i < spName.Length; i++)
                {
                    SqlCommand cmd = CreateCommand(spName[i], (SqlParameter[])al[i], true);
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }

                blret = true;
                Sqltx.Commit();
            }
            catch (SqlException sqlex)
            {
                // Specific catch for deadlock
                if (sqlex.Number != 1205)
                {
                    if (Sqltx != null)
                    {
                        //回滚事物
                        Sqltx.Rollback();
                    }
                }
                ErrorMsg = DBErrorMessageHelper.GetErrorDesc(sqlex.Number.ToString(), sqlex.Message);
                ErrorID  = sqlex.Number;
                if (ErrorMsg == "")
                {
                    throw (sqlex);
                }
            }
            catch (Exception ex)
            {
                if (Sqltx != null)
                {
                    //回滚事物
                    Sqltx.Rollback();
                }
                throw (ex);
            }
            return(blret);
        }
Esempio n. 3
0
        public int RunProcReturn(
            string procName,
            SqlParameter[] prams,
            ref int ErrorID,
            ref string ErrorMsg)
        {
            int intVal = 0;

            try
            {
                ///建立事物处理
                Sqltx = SqlCn.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

                SqlCommand cmd = CreateCommand(procName, prams, true);
                cmd.Prepare();
                cmd.ExecuteNonQuery();
                intVal = Convert.ToInt32(cmd.Parameters[prams.Length - 1].Value);

                cmd.Dispose();
                Sqltx.Commit();
            }
            catch (SqlException sqlex)
            {
                // Specific catch for deadlock
                if (sqlex.Number != 1205)
                {
                    if (Sqltx != null)
                    {
                        //回滚事物
                        Sqltx.Rollback();
                    }
                }
                ErrorMsg = DBErrorMessageHelper.GetErrorDesc(sqlex.Number.ToString(), sqlex.Message);
                ErrorID  = sqlex.Number;
                if (ErrorMsg == "")
                {
                    throw (sqlex);
                }
            }
            catch (Exception ex)
            {
                if (Sqltx != null)
                {
                    //回滚事物
                    Sqltx.Rollback();
                }
                throw (ex);
            }
            return(intVal);
        }
Esempio n. 4
0
        public bool RunProcRet(
            string procName,
            DataView dv,
            DataView dvParams,
            ref int ErrorID,
            ref string ErrorMsg)
        {
            bool blret = false;

            try
            {
                if (dv != null && dvParams != null && dvParams.Count > 0 &&
                    dv.Count > 0)
                {
                    ///建立事物处理
                    Sqltx = SqlCn.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

                    for (int i = 0; i < dv.Count; i++)
                    {
                        SqlParameter[] prams = new SqlParameter[dvParams.Count];
                        for (int j = 0; j < dvParams.Count; j++)
                        {
                            prams[j] = new SqlParameter();

                            prams[j].ParameterName = "@" + dvParams[j]["ParameterName"].ToString().Trim();
                            prams[j].SqlDbType     = GetSqlDbType(dvParams[j]["SqlDbType"].ToString().Trim());

                            if (dvParams[j]["Size"] != System.DBNull.Value &&
                                Convert.ToInt32(dvParams[j]["Size"]) > 0)
                            {
                                prams[j].Size = Convert.ToInt32(dvParams[j]["Size"]);
                            }

                            if (dv[i][dvParams[j]["ParameterName"].ToString().Trim()].ToString().Trim() != "")
                            {
                                prams[j].Value = dv[i][dvParams[j]["ParameterName"].ToString().Trim()];
                            }
                            else
                            {
                                prams[j].Value = System.DBNull.Value;
                            }
                        }

                        SqlCommand cmd = CreateCommand(procName, prams, true);
                        cmd.Prepare();
                        cmd.ExecuteNonQuery();
                    }

                    blret = true;
                    Sqltx.Commit();
                }
            }
            catch (SqlException sqlex)
            {
                // Specific catch for deadlock
                if (sqlex.Number != 1205)
                {
                    if (Sqltx != null)
                    {
                        //回滚事物
                        Sqltx.Rollback();
                    }
                }
                ErrorMsg = DBErrorMessageHelper.GetErrorDesc(sqlex.Number.ToString(), sqlex.Message);
                ErrorID  = sqlex.Number;
                if (ErrorMsg == "")
                {
                    throw (sqlex);
                }
            }
            catch (Exception ex)
            {
                if (Sqltx != null)
                {
                    //回滚事物
                    Sqltx.Rollback();
                }
                throw (ex);
            }
            return(blret);
        }