Using VB 2008 find out who is using access databae

  • Thread starter Thread starter Ralph Malph
  • Start date Start date
R

Ralph Malph

I have a VB 2008 that uses an Access 2000 database to hold the programs data
etc. I need to add some database maintenance functions in to the program such
as database compacting and repairing and data backup and restore.

The database file is stored on a file server.

In VB 2008, how can I query the database to see if anyone is currently using
it before I do any maintenance on it?

If someone does have the database open, how can I force them out prior to
doing the maintenance, or at least identify them so that they can be found
and asked to log off etc.?

Thanks for any help you can provide,

Ralph Malph
 
Ralph said:
I have a VB 2008 that uses an Access 2000 database to hold the programs data
etc. I need to add some database maintenance functions in to the program such
as database compacting and repairing and data backup and restore.

The database file is stored on a file server.

In VB 2008, how can I query the database to see if anyone is currently using
it before I do any maintenance on it?

Even if you could, it was useless. If you do something like

if not locked then
maintenance
end if

it could be locked _after_ the check - that returns that it is not locked - and
before the maintenance. Not very probable, but I think you want it bulletproof.

If someone does have the database open, how can I force them out prior to
doing the maintenance, or at least identify them so that they can be found
and asked to log off etc.?

Thanks for any help you can provide,

Try to catch the exception. The error message may contain a text like
"...is currently locked by user <user>...", but I'm not sure.

Any further self-established information about users "logged into the
database" is as unsure as the locking information described above.
In addition, if a client crashes, it is still recorded as "logged in"
even if he is not.

I don't know if there's a built-in way to get a snapshot of who's opened
the file. I doubt there is one.
 
Actually you can check pretty easy if someone is using the Access database
if there is a ldb file then someone is using the database (
databasename.ldb ) the ldb file is the Access lock file

wich is always created unless you have a readonly connection specified on
the connection ( wich is normally only done for reading the db from a
cd-rom )


HTH

Michel Posseth [MCP]
 
Michel said:
Actually you can check pretty easy if someone is using the Access database
if there is a ldb file then someone is using the database (
databasename.ldb ) the ldb file is the Access lock file

wich is always created unless you have a readonly connection specified on
the connection ( wich is normally only done for reading the db from a
cd-rom )


Right, didn't think of that. However, if the check says the ldb doesn't exist,
it can be created after the check and before trying to exclusively open the file.
That's why I meant with a "useless" check. And soemtimes the ldb is left even
if all clients have closed the file.
 
And soemtimes the ldb is left even
if all clients have closed the file.

Well a dirty trick i used in the past ( VB6 when i actually used Access )
was to
try to delete the ldb file to be sure ,check for existence , then try to
delete when a user is in the database the ldb file is locked (you get an
exception when trying to delete the file ) if it is left over from a
unexpected shutdown of an app it is not .

dirty i know but it works :-)

Michel
 
Back
Top