views:

426

answers:

3

Is there a way to open a MS Access database from VB 6.0 that is being used by another user.

I have a service that is updating a .mdb file. I want to monitor this DB by reading some parameters from it periodically.

If I try to simply open the DB (which works if the DB is not used) like this:

Private Sub Form_Load()
Dim CurrentDBFileName
On Error GoTo ErrorHandler
    Set BaseDB = OpenDatabase("c:\temp\log_db.mdb")
    Set DestRS = BaseDB.OpenRecordset("current_log_info", dbOpenDynaset)
    DestRS.MoveFirst
    CurrentDBFileName = DestRS!CurrentDB
    BaseDB.Close
ErrorHandler:
    Debug.Print Err.Number; Err.Description
End Sub

The error I get:

3051 The Microsoft Jet database engine cannot open the file 'b:\log_db.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

How can I get around this?

I can not change the service updating the MDB file since it is not mine.

+2  A: 

Try:

Set BaseDB = OpenDatabase("gui_db.mdb", false)

To open the database in shared mode. Note that all clients must open the database in shared mode.

Shiraz Bhaiji
+1  A: 

This should be a comment to Shariz, but my rep isn't high enough yet.

Shariz, your code is essentially identical to the code the OP is using as False is the default option for the OpenDatabase method.

To the OP, posting more of the code that you are using might be helpful to diagnose the problem, seeing how there is nothing immediately wrong with the one line of code you posted.

KevenDenen
But wasn't the posted code sample within the *second* process, that is failing? I think the point was that the user program which opened it first needs to open the MDB in shared mode.
Bob Riemersma
A: 

Of course, the best option is to convince the person who wrote the updater service that it should really open the database in shared mode, not exclusive mode.

Another option might be to split the mdb table you want to update out into a separate backend (either another Access database, or SQL Server). Then if the service opens the frontend file exclusively, your backend file should still be shared. The updater service shouldn't be able to see the difference.

apenwarr