Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Locking a table row for one user
Message
De
28/08/2015 07:34:09
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turquie
 
 
À
28/08/2015 05:13:03
Rob Clapworthy
Bespoke Software Systems
Royaume Uni
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01623931
Message ID:
01623935
Vues:
54
>Hi
>
>I am trying to lock a table row in a table that manages field no sequences
>
>Here's my code:
>
>
BEGIN TRAN
>
>SELECT * FROM NEXTID WITH (HOLDLOCK, ROWLOCK) WHERE Cdbfname = 'JOBNO'
>
>mjobno=sqlResults.iNextNo
>
>UPDATE NEXTID SET iNextNo=InextNo+1 FROM NEXTID WITH (HOLDLOCK, ROWLOCK) WHERE Cdbfname = 'JOBNO'
>
>/* Do all your stuff here while the record is locked */
>
>COMMIT TRAN
>
>
>Basically I want one user to go through this code at a time, I thought the begin tran would
>do what I want?
>
>EDIT: I have selected Internet application in the desc, but it is should say desktop application :)
>
>Any help extremely appreciated

I think you don't need any parameters like holdlock or rowlock between begin and end tran. But you have to use begin/end trans carefully. You may cause deadlock.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform