Urgent problem: Any help greatly appreciated

From: Simon Harvey (simon.harvey_at_the-web-works.co.uk)
Date: 06/10/04


Date: Thu, 10 Jun 2004 15:49:47 +0100

Hi everyone,

I'm having a problem that I don't know how to sort.

I am trying to execute a number of SQL stored procedures in a single
transaction. However it always throughs an exception saying that the "Thread
was being aborted"
I really need to be able to execute these procedures in a single transaction
so that the data doesnt become corrupt.

If anyone could help me I would be very greatful.

Sincerest thanks and kindest regards

Simon

public static bool executeBatchTransaction(ArrayList cmds){
 SqlConnection con = new SqlConnection(connectionString);
 IEnumerator cmdEnumerator;
 SqlCommand currentCmd;
 SqlTransaction trans;
 DataSet dataset = new DataSet();

 // Get this command seperately so we can start the transaction
 currentCmd = (SqlCommand)cmds[0];

 // We can't put this in a try block because if con.open fails, trans wont
be assigned to and we'll
 // get an unassigned variable. Wont compile
 // Start the transaction
 currentCmd.Connection = con;
 currentCmd.Connection.Open();
 trans = currentCmd.Connection.BeginTransaction();
 currentCmd.Transaction = trans;

  // Execute the first command seperately
  try{
   if(!executeNonQuery(currentCmd)){
    trans.Rollback();
    return false;
   }
  }
  catch(Exception e){
   trans.Rollback();
   ExceptionManager.Publish(new Exception("Exception detected whilst
executing DataAccessProvider.executeBatchTransaction(ArrayList cmds", e ));
   MiscLogic.redirectOnError("/errors/defaultErrorPage.aspx");
  }

  cmdEnumerator = cmds.GetEnumerator();
  // Skip the first command
  cmdEnumerator.MoveNext();

  while(cmdEnumerator.MoveNext()){
   currentCmd = (SqlCommand)cmdEnumerator.Current;
   try{
    if(executeNonQuery(currentCmd)){
     continue;
    }
    else{
     trans.Rollback();
     return false;
    }
   }
   catch(Exception e){
    trans.Rollback();
    ExceptionManager.Publish(new Exception("Exception detected whilst
executing DataAccessProvider.executeBatchTransaction(ArrayList cmds", e ));
    MiscLogic.redirectOnError("/errors/defaultErrorPage.aspx");
   }
  }

 // If we get to here all the commands executed successfully. Commit and
return
 trans.Commit();
 return true;

}



Relevant Pages

  • Re: Concurrent Connections / Shared Transaction
    ... In MARS there are fixed interleave points in the server. ... Do you mean that one will execute and ... bound sessions allow you to share the transaction space among ...
    (microsoft.public.dotnet.framework.adonet)
  • Urgent problem: Any help greatly appreciated
    ... I am trying to execute a number of SQL stored procedures in a single ... I really need to be able to execute these procedures in a single transaction ... SqlTransaction trans; ...
    (microsoft.public.dotnet.languages.csharp)
  • Urgent problem: Any help greatly appreciated
    ... I am trying to execute a number of SQL stored procedures in a single ... I really need to be able to execute these procedures in a single transaction ... SqlTransaction trans; ...
    (microsoft.public.dotnet.general)
  • Re: Concurrent Connections / Shared Transaction
    ... Do you mean that one will execute and ... bound sessions allow you to share the transaction space among ... > connections but doesn't give you concurrent access to it. ... > Server 2005 you can mix MARS plus asynchronous command execution to submit ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Urgent problem: Any help greatly appreciated
    ... > I am trying to execute a number of SQL stored procedures in a single ... Second don't do a ASP.NET redirect in this function. ... public static SqlConnection connect ...
    (microsoft.public.dotnet.general)