This question may seem very very easy (Select COUNT(Id), but in my case is different. I developed a web application with 15 to 25 concurrent users. every time they open the program, I am checking the last row inserted into the database and in C# I created a serial number based on the last row inserted + 1. So say for example below entry:
User1 opens up the program:
DB count = 1
C# Series = Ser-00001 (displayed in UI)
User1 inserts a row. success
User2 opens up the program:
DB count = 2
C# Series = Ser-00002 (displayed in UI)
User2 inserts a row. success
User3 opens up the program:
DB count = 3
C# Series = Ser-00003 (displayed in UI)
User3 inserts a row. success
No issue right? But, there will be a time that 2 or more users will open the program at the same time. Now, below is the scenario
User7 opens up the program:
DB count = 4
C# Series = Ser-00004 (displayed in UI)
User7 inserts a row. success
User8 opens up the program:
DB count = 4
C# Series = Ser-00004 (displayed in UI)
User8 inserts a row. failed
User9 opens up the program:
DB count = 4
C# Series = Ser-00004 (displayed in UI)
User9 inserts a row. failed
This time a big problem suddenly occur!
Now my question is, how do you do it to avoid this type of duplication? Thank you in advance for any posible solution.


Siddharth GajbhiyeRank #376 · 6.7K reputationPosted Apr 7, 2021, 12:06 AM EDT
Salman BegRank #284 · 8.8K reputationPosted Apr 6, 2021, 2:09 PM EDT
Sundaram SubramanianRank #150 · 15.2K reputationPosted Apr 6, 2021, 10:05 PM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Apr 6, 2021, 11:38 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Apr 7, 2021, 4:01 AM EDT
Jes SieRank #1,285 · 1.3K reputationPosted Apr 25, 2021, 9:45 PM EDT