• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 149
  • Last Modified:

Locking records in a multiuser environment

hello everybody,

I am trying to create a vb appln that will be used in a multi user environment.

i have a table with fields like
1. id - number
2. name - text

i get duplicate id's when more than one user tries to update that table.

how to resolve this concurrency problem?

plz help me out.

thanks in advance
  • 2
  • 2
1 Solution
Which DB you are using at the back end?

In any case, A better solution is to use SELECT...FOR UPDATE to lock the selected rows. Another user cannot modify the row between the SELECT...FOR UPDATE and UPDATE. In fact, the row remains locked until the transaction ends.


SELECT * FROM Test WHERE name = 'karc' FOR UPDATE;

UPDATE Test SET name = 'Origin' WHERE name = 'karc';

I hope it helps you.

If the id field is the primary key, the table would automatically reject duplicate value.
If you still want to make sure, if you are using MS SQL, you can create a stored procedure to handle the insert, update and delete process.
In the stored procedure, do the insert stuff inside a transaction , the transaction will lock the table temporaryly until it is committed. And also during the transaction check for duplicate value before updating the table.
Hope that help.
eskillAuthor Commented:
I am using MSAccess 2000 as the back end
Maybe this will help.
In the field property set indexed value to Yes (No Duplicates).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now