Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 19,255 of 19,505    |
|    rja.carnegie@gmail.com to Erland Sommarskog    |
|    Re: Using sp_getapplock outside a transa    |
|    27 Nov 17 14:23:04    |
   
   On Monday, 27 November 2017 10:56:34 UTC, Erland Sommarskog wrote:   
   > Anton Shepelev (anton.txt@g{oogle}mail.com) writes:   
   > > Indeed. An inner BEGIN TRAN only increments the   
   > > counter, an inner COMMIT TRAN decrements it, but (!)   
   > > ROLLBACK TRAN does actually undo the the outer   
   > > transaction and sets the counter to zero. This is   
   > > all very unintuitive to me, and requires special   
   > > handling of ROLLBACKs in both T-SQL code and the   
   > > client application.   
   > >   
   >   
   > It becomes more intuitive if you stop to think in terms of "outer   
   > transaction". A transaction is all there is. So the ROLLBACK will   
   > roll back it all.   
   >   
   > The point with BEGIN/COMMIT increase @@trancount is that it makes   
   > it easier to nest procedures that both start transactions.   
      
   Either my own understanding is wrong, or you should say,   
   "Do not think in terms of outer transaction" - because   
   the phrase "stop to think" has a different meaning.   
      
   I think we are agreeing that a transaction starts when   
   "BEGIN TRAN" first appears - or automatically if a certain   
   setting is in place (which I've forgotten) - and ends either   
   immediately at ROLLBACK TRAN, or else when the number of   
   COMMIT TRAN statements equals the number of implicit   
   and explicit BEGIN TRAN. Naming the BEGIN TRAN statements   
   does not get around this: only the outermost transaction name   
   can be addressed. Using transaction savepoints does get   
   around it in a way...   
      
   Also, we should avoid having long transactions: they block   
   other business and (with simple recovery) they bloat the   
   log file. But if it's your own server then do whatever   
   you want!   
      
   I think Anton got the out-of-transaction lock to work,   
   but I've rather lost track of the conversation.   
   i.e. one term needed to be added to the "release" statement:   
      
    EXEC sp_getapplock 'test', 'Exclusive', @LockOwner = 'Session'   
    EXEC sp_releaseapplock 'test', @LockOwner = 'Session'   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca