views:

19

answers:

1

I've been reading up on SqlTransactions and have found a great load of examples like: http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=451

The problem is, when I do a BeginTransaction() (Execute all the commands) and then Commit() at the end all the commands I execute get run and the ones with syntax errors or other errors just get skipped. This is where I would also like to run a roll back, not skip over them. I found a few articles on the subject but they were not very helpful and purely in SQL.

Is there any way to find out if one of the ExecuteNonQuery()'s failed before the commit and not just skipped? Thanks.

A: 

You're mistaken.

  1. Commands execute when you execute them. They just don't get their changes committed right away.
  2. Commands with errors do not "get skipped". They throw exceptions at the time they are executed.

If you're doing things properly, you won't execute a Commit when exceptions have been thrown, and the transaction will roll back.

The very example you cited shows this. See line 36.

John Saunders
Strange, must have been something I skipped or overlooked during execution. Thanks.
Sam F
Ah I see where the problem was. Before I found that example I was viewing one that did not have the command.Transaction = myTransaction; Now it is working as I thought it originally would rolling back after putting intentional errors in the SQL syntax.
Sam F