Re: Using a Transaction with a SqlDataSource
- From: "Mr. Arnold" <MR. Arnold@xxxxxxxxxx>
- Date: Thu, 17 May 2007 13:30:17 -0400
"Steven Blair" <steven.blair@xxxxxxxxxxxxxx> wrote in message news:eNBUKdImHHA.4768@xxxxxxxxxxxxxxxxxxxxxxx
I have a problem on my SqlDataSource.
Once my SqlDataSource has Inserted, I need to run a stored procedure.
The return from this stored procedure determines if Icommit or rollback.
Here is my approach:
http://rafb.net/p/b53pmq89.html
When the ExecuteNonQuery is fired the following exception is thrown:
"Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK
TRANSACTION statement is missing. Previous count = 1, current count =
0."
Anyone know what the problem is, or is my approach wrong?
e.Command.Transaction.Commit() should be placed right after e.Command.ExecuteNonQuery(), because the execution of the StoreProcedure returned good. It took the non-exception path, the transactions should be committed. What are you wafting for?
The e.Command.Transaction.Rollback() should be placed in the scope of the Catch, with a possible check to see if the connection is Open and close the connection before you Throw (ex) to leave the routine.
The Finally should be checking for connection Open and Close the connection if open.
Have you heard of the ADO.Net Using statement, which should not to be confused with the Namespace Using statement, use Google and look it up.
..
.
- Follow-Ups:
- Re: Using a Transaction with a SqlDataSource
- From: Steven Blair
- Re: Using a Transaction with a SqlDataSource
- References:
- Using a Transaction with a SqlDataSource
- From: Steven Blair
- Using a Transaction with a SqlDataSource
- Prev by Date: Re: ASP.Net - Repeater Control - 3 Columns - Unlimited Rows
- Next by Date: Re: foreach listviewitem in a background thread
- Previous by thread: Using a Transaction with a SqlDataSource
- Next by thread: Re: Using a Transaction with a SqlDataSource
- Index(es):
Relevant Pages
|