Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Nested Commit while rollback transaction Expand / Collapse
Author
Message
Posted Friday, January 25, 2008 1:48 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, March 24, 2010 1:57 PM
Points: 182, Visits: 65
I know that I have done this before, but cannot find my code.

I am debugging a complex set of stored procedures. These procs are executed within a transaction from an online application. The errors do not occur when running the procedure in my query editor.

What I am looking to do is write out a row to a progress tracking table, but my problem is that when the error occurs, everything gets rolled back including my trace. my output table would contain something like the following with datetime and spid information as well...

exec procedure 1
exec proc 2
exec proc 3
exec proc 4
exec proc 5

Anyone have the code that will allow me to commit these rows while leaving the outer transaction in place?

Thanks in advance
Eric Peterson

Post #447802
Posted Monday, January 28, 2008 3:07 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
The only solution I can easily think of is write to a log file instead of a log table. Rollback won't "unwrite" the log file.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #448609
Posted Monday, January 28, 2008 3:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:27 PM
Points: 7,120, Visits: 15,016
Per Books Online:

Committing inner transactions is ignored by the SQL Server Database Engine. The transaction is either committed or rolled back based on the action taken at the end of the outermost transaction. If the outer transaction is committed, the inner nested transactions are also committed. If the outer transaction is rolled back, then all inner transactions are also rolled back, regardless of whether or not the inner transactions were individually committed.


The rest is here: http://msdn2.microsoft.com/en-us/library/ms189336.aspx

So - it sounds like you're stuck unless you can set up the outer process outside of a "traditional transaction"....


----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #448625
Posted Wednesday, January 30, 2008 11:48 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, April 20, 2014 7:48 PM
Points: 34, Visits: 74
You can use table variable for ur tracking data, u can insert the tracking data into it between the transactions and finally it wouldn't be removed after even roll back of the transaction. At the end, after the transaction, u can insert the data from ur table variable to ur physical tracking table.

hope it helps.
-Shashi
Post #449822
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse