[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-13
6
Medium Priority
?
470 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:xjpmauricio
  • 2
4 Comments
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16445484
0
 
LVL 1

Author Comment

by:xjpmauricio
ID: 16445528
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!
0
 
LVL 1

Author Comment

by:xjpmauricio
ID: 16445534
this is a sql server related problem, not a response.redirect problem i think! ...
0
 
LVL 3

Accepted Solution

by:
yokkui earned 660 total points
ID: 16602330
Use Int32.ToString() for the parameters and HttpResponse(message, false) so that the current page won't stop the execution before the db connection is closed.

Try this:

...preceding code...

 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.ToString() + " \n";

...code...

                    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.ToString() + " \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()), False);
               }

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

          }

Hope this helps.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Simple Linear Regression
Starting up a Project

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question