Accessing a record at the same time, two different machines

prabumj

Member
Joined
Jul 25, 2007
Messages
15
Location
India
Programming Experience
1-3
I hav A FORM maintaining product details (Product ID is primary key) connected to sqlserver , and the FORM is installed on two different system , if both person in two diff system accessed the FORM at a same time which results in getting Same ProductID in both the system and results in error while insert button is pressed by both (which is primary key error from sqlserver). wat is the way to avoid this kind of problems.
Any One!
 
have the database calculate the ID upon insertion. It is logically impossible for the database to perform 2 inserts at the same time
 
SQL Server

Product Table, ProductID column -
Identity = Yes
IdentitySeed = 1
IdentityIncrement = 1

Your Dataset

Product DataTable, ProductID column -

AutoIncrement = True
AutoIncrementSeed = -1
AutoIncrementStep = -1


By doing it this way, your app doesn't designate the ID. By using the -1 , it won't take the next ID from your application, instead, once you submit, it will get the correct Identity (the next logical increment) set to it from the SQL Server.

TBH, if you are using an app that inserts data on more than one client, I would always use the above advice.
 
Back
Top