I have been placing set xact_abort on
into SQL command statements and noticed that it is not rolling back updates, inserts, etc in my C# SqlCommand
on error. Taken from this post. The MSDN states that:
When SET XACT_ABORT is ON, if a Transact-SQL statement raises a run-time error, the entire transaction is terminated and rolled back.
The general format of my SQl query is:
set xact_abort on
INSERT INTO Table1
UPDATE Table2
UPDATE Table3
UPDATE Table4
--Finally
SELECT someValue
I noticed that on error my SQL command was not being rolled back. The particular error is this case was that the data length of one parameter exceeded the columns specified length. I am using SqlCommand
and SqlParameter
to create SQL queries.
I am not looking to handle the exceptions in SQL, but it is very important that any errors do not commit any changes to the database.
Typically errors include: column does not exist, wrong data type, data would be truncated due to length, etc.
Should I be using something other than set xact_abort on
? Thanks in advance!