Solved

Locking records in a multiuser environment

Posted on 2004-08-30
5
143 Views
Last Modified: 2010-05-02
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
sarni
0
Comment
Question by:eskill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 11929401
Which DB you are using at the back end?
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 11929417

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.


Eg:

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

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

I hope it helps you.

Cheers!
0
 
LVL 5

Accepted Solution

by:
Z03niE earned 125 total points
ID: 11929443
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.
0
 

Author Comment

by:eskill
ID: 11929548
I am using MSAccess 2000 as the back end
0
 
LVL 5

Expert Comment

by:Z03niE
ID: 11929581
Maybe this will help.
In the field property set indexed value to Yes (No Duplicates).
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question