Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2007-07-02 : 19:41:13
|
| I have a stored procedure(sp_log_error) which basically logs in an error log table. This stored procedure has its own begin trans and commit / rollback trans statements.This procedure is called by various other procedures to log the error messages, the problem is when I roll back the parent procedure any changes made by sp_log_error is also rolled back. Any way I can avoid it?ThanksKarunakaran |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-07-02 : 20:18:51
|
| Do you need to put this proc in a transaction if you are just logging errors?Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2007-07-02 : 20:39:51
|
quote: Originally posted by dinakar Do you need to put this proc in a transaction if you are just logging errors?Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/
I'm assuming you are asking about the transaction inside the error logging sp, If that is the case, as long as I can log the errors I can take out the transaction from the error logging sp.ThanksKarunakaran |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-07-03 : 13:49:28
|
If you call your error logging proc from inside the parent tansaction and then roll it back it will rollback whatever was done in the child proc. For example:CREATE TABLE #Temp (ID INT)INSERT #TempSELECT 1UNION ALL SELECT 2UNION ALL SELECT 3BEGIN TRANSACTION UPDATE #Temp SET ID = 10 WHERE ID = 3 BEGIN TRANSACTION INSERT #Temp SELECT 99 COMMIT TRANSACTIONROLLBACK TRANSACTIONSELECT *FROM @Temp So in order to avoid the error logging from rolling back you would need to do the rollback, then log the error. Hopefully, that makes sense.-Ryan |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|