Monday, March 19, 2012

How to log errors within a transaction and survive a ROLLBACK

Within a transaction, want to be able to log errors to an activity log
table but if errors occur and a ROLLBACK is invoked the errors logged
to the activity log table get rolled back also. What's the best way
to handle this situation?william@.accupointe.com wrote:
> Within a transaction, want to be able to log errors to an activity log
> table but if errors occur and a ROLLBACK is invoked the errors logged
> to the activity log table get rolled back also. What's the best way
> to handle this situation?
Write the data in the log table after you perform the rollback (keep
the values in some variables when you rollback). If you need to log
multiple rows, you can temporarily store the values in a table
variable, which is not affected by a ROLLBACK.
--
Razvan Socol
SQL Server MVP

No comments:

Post a Comment