Solved

ACCESS - Lock tables against all except my procedure

Posted on 2004-08-24
9
246 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Accepted Solution

by:
fulscher earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

747 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

9 Experts available now in Live!

Get 1:1 Help Now