Solved

Locking records in a multiuser environment

Posted on 2004-08-30
5
138 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now