assigning a serial number to a client from a pool of serial numbers

HakuAnime

New Member
I have a sql server table of licence keys/serial numbers.Table structure is something like;[RecordId int,LicenceKey string,Status int (available, locked, used, expired etc.)AssignedTo int (customerId)....]Through my ASP.NET application, when the user decides to buy a licence clicking the accept button, i need to reserve a licence key for the user.My approach is like, Select top 1 licenceKey from KeysTable Where Status = availableUpdate KeysTable Set status = lockedthen return the key back to the application.My concern is, if two asp.net threads access the same record and returns the same licencekey. What do you think is the best practice of doing such assignments ? Is there a well known aproach or a pattern to this kind of problem ?Where to use lock() statements if i need any ?I'm using Sql Server 2005, stored procedures for data access, a DataLayer a BusinessLayer and Asp.Net GUI.Thanks
 
Back
Top