Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I want to rollback transaction partially. Actually I have a procedure which does some tasks. I want to log the state of on each step. For this want to insert a row in the log table. In case of any exception I want to know how many steps are executed completely and on which step exception occurred.

Currently if any exception occurred then all the changes in database are rolled back. If there is any workaround for this then please let me know.

What I have tried:

I am still finding a soln for this.
Posted
Updated 29-Jun-16 21:27pm

1 solution

You can't rollback "part" of a transaction - it's all or nothing.
Even if you nest transactions, inner level COMMIT instructions are ignored, and inner level ROLLBACK will cause an error: Nesting Transactions[^]
To insert a log entry which won't be rolled back regardless of the transaction is possible (but nasty) - use xp_cmdshell and execute osql with an INSERT statement into your log. It'll work - because it's a separate session - but it'll be dog slow!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900