Urgent problem: Any help greatly appreciated
From: Simon Harvey (simon.harvey_at_the-web-works.co.uk)
Date: 06/10/04
- Next message: Jack: "Re: How do I define an XML schema to support a GUID primary key?"
- Previous message: PeteJ: "Re: How do I define an XML schema to support a GUID primary key?"
- Next in thread: chanmmn: "Re: Urgent problem: Any help greatly appreciated"
- Reply: chanmmn: "Re: Urgent problem: Any help greatly appreciated"
- Reply: David Browne: "Re: Urgent problem: Any help greatly appreciated"
- Messages sorted by: [ date ] [ thread ]
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;
}
- Next message: Jack: "Re: How do I define an XML schema to support a GUID primary key?"
- Previous message: PeteJ: "Re: How do I define an XML schema to support a GUID primary key?"
- Next in thread: chanmmn: "Re: Urgent problem: Any help greatly appreciated"
- Reply: chanmmn: "Re: Urgent problem: Any help greatly appreciated"
- Reply: David Browne: "Re: Urgent problem: Any help greatly appreciated"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|