Search code examples
c#mysqlasp.netmultiple-users

Put users commands on hold while other user's command finished ASP.Net


I'm building a web app using asp.net and C#. The app has multiple users working simultaneously and entering families info -including family members' info- to it. The IDs for the family members are generated using an algorithm specific to the app and so are the IDs for the families based on the last ID in table, but when testing, if two users entered two separate families' info at the same time, the IDs would interfere into each others causing primary key duplication. Any thoughts on how to put other users processes on hold while a user is entering data? I'm using ASP.Net, C# and MySQL.


Solution

  • From your post, 2 possible solutions

    1. Use incremental primary key (when you put record to database, database assign new unique value). Database generates new key automatically

    2. Add Sequence for primary key. When you save a row, first ask database for next sequence value, and use the result as the primary key value. Sequence guaranteed that key will be unique.