Beispiel #1
0
 public DBTransaction(StateBag sb)
 {
     SB = sb;
     CreateTransaction();
 }
Beispiel #2
0
 public Boolean Execute(StateBag sb)
 {
     //execute
     db.ExecuteReader(sb);
     return(sb.Valid);
 }
Beispiel #3
0
        public void ExecuteReader(StateBag sb)
        {
            if (sb.Valid)
            {
                if (sb.Tn == null)
                {
                    if (ConfigurationManager.ConnectionStrings["connstr"] == null)
                    {
                        throw new Exception("Add connection string 'connstr' to web.config");
                    }
                    conn           = new SqlConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
                    cmd.Connection = conn;
                }
                else
                {
                    conn            = sb.Tn.Connection;
                    cmd.Connection  = conn;
                    cmd.Transaction = sb.Tn;
                }



                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                //store SP for error logging
                if (HttpContext.Current != null && HttpContext.Current.IsDebuggingEnabled)
                {
                    if (HttpContext.Current.Items.Contains("LastSP"))
                    {
                        HttpContext.Current.Items["LastSP"] = DumpSqlData();
                    }
                    else
                    {
                        HttpContext.Current.Items.Add("LastSP", DumpSqlData());
                    }
                }

                //EXECUTE
                if (sb.Valid)
                {
                    SqlParameter retval = new SqlParameter("RetVal", SqlDbType.Int);
                    retval.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retval);
                    try
                    {
                        dr = cmd.ExecuteReader();
                    }
                    catch (Exception ex)
                    {
                        //if (sb.Tn != null)
                        //{
                        //System.Diagnostics.Debug.Assert(false, ex.ToString());
                        sb.ErrorMsg = ex.Message.ToString();
                        //}
                    }
                }
            }

            //check result error
            CheckForErr(ref sb);
        }