Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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?

Thanks
BV
Posted
Updated 2-Jul-17 18:08pm
Comments
E.F. Nijboer 4-Jul-12 4:29am    
Table level locks? Are you using a database? In that case, use an auto incremented field.
Balaji1982 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.
Format:
YYYYMMDD+MAX(COUNT(*) FROM TABLE)

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.
Balaji1982 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900