Link to home
Start Free TrialLog in
Avatar of xjpmauricio
xjpmauricio

asked on

ERROR: Thread was being aborted ... Please Help!

i have this code wich works fine with 20-30 records but, if i use it with 120 records or more i get the "Thread was being aborted" error! what's happening? here's the code:

            //****************************************************************************
            //1 - Closes order
            private void closeOrder()
            {
                  //OrderType: collectInCustomer || deliverToCustomer      
                  if(orderType.Value.Trim() == "collectInCustomer")
                  {
                        //collectInCustomer » Stored
                        __mediaLocationStateFlags = "Stored";
                  }
                  else
                  {
                        //deliverToCustomer » IntheCustomer
                        __mediaLocationStateFlags = "IntheCustomer";
                  }
 
//                  Response.Write("status: " + __mediaLocationStateFlags +
//                        "<br>OrderID: " + _orderID);

                  
                  SqlConnection conn = new SqlConnection(_getSetting.mssqlsConn);
                  //[ 1 ] ....................................................................
                  //Selects Current order items - Loop
                  strCommand = "/* [ 1 ] Lists order media items - processOrder.aspx */ \n" +
                        "select * from EAD_ORDERS where OrderId = " + _orderID + "\n";

                  try
                  {
                        conn.Open();

                        SqlCommand cmd = new SqlCommand(strCommand,conn);
                        SqlDataReader reader = cmd.ExecuteReader();

                        while(reader.Read())
                        {
                              //Response.Write("item: " + reader["mediaID"].ToString() + "<br>");
                              closeOrderExec(Convert.ToInt32(reader["OrderID"].ToString().Trim()),
                                    Convert.ToInt32(reader["mediaID"].ToString().Trim()),
                                    __mediaLocationStateFlags);
                        }
                        reader.Close();
                  }

                  catch(Exception ex)
                  {
                        conn.Close();
                Response.Redirect("message.aspx?message=Erro closeOrder: " + Server.UrlEncode(ex.Message.ToString()));
                  }

                  finally
                  {
                        if (conn.State == ConnectionState.Open)
                              conn.Close();
                  }


                  //Order confirmation alert box - order processed ok
                  Page.RegisterStartupScript("orderProcessed",
                        "<script>\n" +
                        "alert('Pedido fechado com sucesso.'); \n" +
                        "location.href='processOrder.aspx?orderID=" + _orderID +
                        "&filter=Processed&orderType=" + _orderType + "';\n" +
                        "</script>\n");


//                        "location.href='listOrders.aspx?" + _orderID +
//                        "&filter=Processed'; \n" +
            }



            //******************************************************************************
            //2 - closeOrderExec
            private void closeOrderExec(int OrderID, int mediaID,
                  string __mediaLocationStateFlags)
            {
                  
                  SqlConnection conn = new SqlConnection(_getSetting.mssqlsConn);
                  conn.Open();

                  SqlCommand myCommand = conn.CreateCommand();
                  SqlTransaction myTrans;

                  myTrans = conn.BeginTransaction();
                  myCommand.Connection = conn;
                  myCommand.Transaction = myTrans;

                  try
                  {
                        //EAD_ORDERS
                        //Updates order state: OrderState from open to Processed
                        myCommand.CommandText = "/* [ 1.1 ] EAD_ORDERS - OrderState from open to Processed */ \n" +
                              "update EAD_ORDERS set OrderState = 'Processed', \n" +
                              "processingTimeStamp = getDate() \n" +
                              "where OrderID = " + OrderID + " \n";

                        //reader["OrderID"].ToString().Trim()
                        myCommand.ExecuteNonQuery();


                        //EAD_MEDIA_MASTER
                        //updates by referencing mediaID, columns MediaLocationState & oficialMediaLocationState
                        myCommand.CommandText = "/* [ 1.2 ] EAD_MEDIA_MASTER - Change MediaLocationState & oficialMediaLocationState */ \n" +
                              "update EAD_MEDIA_MASTER set MediaLocationState = '" + __mediaLocationStateFlags + "', \n" +
                              "oficialMediaLocationState = '" + __mediaLocationStateFlags + "' \n" +
                              "where mediaID = " + mediaID + " \n";
                        //reader["mediaID"].ToString().Trim()
                        myCommand.ExecuteNonQuery();

                        //myCommand.ExecuteNonQuery();
                        myTrans.Commit();
                  }

                  catch(Exception ex)
                  {
                        myTrans.Rollback();
                        conn.Close();
                Response.Redirect("message.aspx?message=Erro closeOrderExec: " + Server.UrlEncode(ex.Message.ToString()));
                  }

                  finally
                  {
                        if (conn.State == ConnectionState.Open)
                              conn.Close();
                  }

            }


i've tried messing with memory settings everywhere, machine.config....everything!!! can someone help me with this?
Avatar of WelkinMaze
WelkinMaze

Avatar of xjpmauricio

ASKER

i tried that but the problem is that no data get's on the SQL server, it's like the queries in the private void closeOrderExec method don't get executed!
this is a sql server related problem, not a response.redirect problem i think! ...
ASKER CERTIFIED SOLUTION
Avatar of yokkui
yokkui
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial