Exclusive access to db

R

rs0905

This is a multi-user db. I would like a way for my code to determine if the
db is currently opened exclusively, or if there are other users using the db.
I have a cmd button that runs code which requires the db to be opened
exclusively.

Is there a line of code I can use that can return if the db is opened
exclusively or not?

maybe "If (database is opened exclusively) then...." ??

Thanks!
 
D

Dale Fye

Do you have your datbase split into front and backend databases?

If so, and you have a Splash form (form that opens first and generally has
some sort of a control panel or switchboard on it), then you can put some
code in the Open or Load event of the form to check to see if there is an
ldb file that exists for the backend database. If so, it means that someone
else has the database open. Actually, this is only true if your Splash
screen does not contain any controls that use any of the tables in the
backend database.

The way I would do it is to check the database property of the mSysObjects
table and determine the name of the backend data file. Then, I would use
the DIR command and pass it the path and name to the database, making sure
to Replace the .mdb with .ldb. If Dir returns a empty string ("") then you
know no one else has the database open. If it finds the ldb file, then you
know at least one other person has it open.

The other thing about this is that the ldb file could be a remnant of a
session that was closed improperly (network connection lost, application
crashed, or some other reason). If the ldb file exists, you might try to
KILL it (deletes the file). If this does not cause an errror, then it was a
remnant, and you now know you are the only one using the file. If it does
cause an error, then you know someone else is using the file and you do not
have exclusive use.

HTH
Dale
 
A

Allen Browne

How about try an OpenDatabase(), with error recovery.

The error message will indicate if it fails because it is already opened
exclusively.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top