Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ACCESS - Lock tables against all except my procedure

Posted on 2004-08-24
9
Medium Priority
?
257 Views
Last Modified: 2009-07-29
I have a bulk update procedure that runs fine when no one else is editing any records.  But, if a record is being edited, my update query just skips it.

Is there any way to lock the table(s) before running my procedure while still allowing it (and only it) to modify the records?

I am not using MS Access security, so everyone is logged in as Admin.

Thanks for your help.

-KP
0
Comment
Question by:Kaprice
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:acampoma
ID: 11889033
You can open a table with exclusive rights and that will lock everyone out
0
 
LVL 1

Expert Comment

by:mlpk_tyr
ID: 11889305
there are different levels of locks available for a database. So you can go for a table level locks or else you can put the update statements inside a transaction so that even if any update fails all the transaction are rolled back. By this method you may have to rerun the procedure even if 1 among 1000 update fails. you can rely on anyone of the methods based on your time and processing environment.

all the best,
mlpk_tyr
0
 

Author Comment

by:Kaprice
ID: 11889816
My procedure is running an UPDATE QUERY.  So, if I open the table wtih exclusive rights, my query won't be able to modify it, either, right?  So, how can I lock the table while still being able to run my update query?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

by:mlpk_tyr
ID: 11890233
i cant follow your statement. but acquire the lock for update operation. as there are differnt locking modes available . So if you acquire a lock that would satisy the need then it will surely do,

all the best,
mlpk_tyr
0
 
LVL 12

Accepted Solution

by:
fulscher earned 1000 total points
ID: 11890385
Kaprice

This is an interesting problem: In Access, users by default do NOT lock a table at all when editing it; a lock is set very briefly when the record is updated. (in the forms designer, "No Lock" in the table / Record Locks property).

This means that if some of your users are currently editing the record, you run your query, and users save their records, the table will be overwritten with the old values.

You can protect yourself against this by using "pessimistic locking" (in the forms designer, use "current record" or "all records". "All records" should be used only if users are editing in the "Single Form" view; if they're working in the "continous form" or "datasheet" view, all visible records will be locked. So, if users are working in the continuous or datasheet view, they are likely to lock themselves out if you use "all records" locking.

Also, Access does not lock individual records, but pages; for small records, a lock could cover more than one record.

So, it really depends a bit on your situation; you'll have to experiment.

You can modify your query to use pessimistic locking (open the query, use Edit/Properties, and set the query "Record Locks" to "All Records").

Hope this helps
Jan
0
 

Author Comment

by:Kaprice
ID: 11959846
Access 2000 has the option of record locking instead of page locking.  And, I've confirmed that if a user is in a table and the pencil is showing, it's in EDIT mode, and an update query will fail on that record.

What I'm not clear on is, if I LOCK a table, how am I able to modify it?  It's locked now?  IOW, I need it locked against everyone else but available to my query.
0
 
LVL 12

Expert Comment

by:fulscher
ID: 11960632
Kaprice,

"Locking" means it is locked against access of anybody EXCEPT your current transaction. In other words: If your transaction locks the table, you can access it, but nobody else. Usually, you would set the lock, run the procedure, remove the lock to make sure that everything is consistent.

Remember that the lock works on a transaction level. If you lock the table using VBA first and then try to run an SQL procedure against it, that's TWO transactions, so the VBA code will win and the SQL procedure will fail.

Hope this helps
Jan
0
 

Author Comment

by:Kaprice
ID: 11970405
OK, so here's a scenario:

In VBA...

Sub Sample
...
...
...
Lock the table
Run an Update Query
Unlock the table
...
...
...
End Sub

That won't work, right?  Because the VBA code locked the table so the Query can't access it, right?

So, what's the solution in this example?
0
 

Author Comment

by:Kaprice
ID: 12012699
Well, I do't have the right answer (though a few hints in the right directioni), here, but Fulscher made the most attempts, so I'll award the points there.

Here's the answer I found on my own:

Apparently, when you execute a query with VBA, there's a parameter for desired lock type.  I can use that parameter to lock the recordset against everyone/everything while allowing the query to run through that code.

Thanks all for your efforts.

-Keith Price
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

876 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