Click here to Skip to main content
13,139,515 members (60,096 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I would like to know the best approach.

I have 10 different screens accessing the same table for an unique order number. Once a screen requests a unique number the same is generated and stored in this table and this value is sent back to the screen. This becomes a problem when the requests are concurrent. We had used table level locks for this purpose. Is there a better approach like request/message/thread queuing so that only one access happens at any point of time and other requests are queued up and serviced async?

Posted 3-Jul-12 22:20pm
Updated 2-Jul-17 18:08pm
E.F. Nijboer 4-Jul-12 4:29am
Table level locks? Are you using a database? In that case, use an auto incremented field.
Member 8648508 4-Jul-12 4:34am
Thanks mate. Auto Increment is not suitable here as this is a Unique Order Number that is being generated. Something like this.

This number for today will be 2012070401, 2012070402, 2012070403....

for tomorrow will be 2012070501, 2012070502 and so on
E.F. Nijboer 4-Jul-12 5:02am
You could of course add another table that has a date and the last identity of that previous day. This way you can get the desired Order number by finding the matching record in the new table within the range. You then take the date and add the identity after you subtract the last identity of the previous date from the record you find. It isn't the most beautiful solution though, but its an idea.
It might actually work if you use this in a two step way to create an id because this way you make sure the id constructed is always unique.
Member 8648508 4-Jul-12 8:26am
Thanks mate. Would this solve 10 or more concurrent requests for unique order number? I would like to keep the current table structure intact if possible and do the queuing only at the C# code level.
E.F. Nijboer 4-Jul-12 9:34am
Well, it must because the identity column is the primary key and therefor unique, otherwise it would violate this contraint.
Member 8648508 9-Jul-12 1:32am
Hi dude, the Identity number must start with 1 daily.

This order number for today will be 2012070901, 2012070902, 2012070903.... for tomorrow will be 2012071001, 2012071002 and so on.

I recon we need to look for a more generic requests queuing system. First in First out implementation.
E.F. Nijboer 9-Jul-12 3:35am
You would need to store the last ID of the day and subtract it from it from each ID the next day. That way it will start with 1 each day.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 3 Jul 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100