err 3051 - trying to open a read-only db

M

Margaret Bartley

DAO 3.6 Access 2000:

Whenever I try to open a database that is read-only, I get
the error 3051 - that I cannot open the file because it is
opened exclusively by another user, or I don't have
permission to read it.

I am working on my local machine, and I know it's not opened
by another user, besides, I get this message whenever, and
only, when I try to open a read-only file. None of these
files have any security on them. I can open them through
the user interface.

This is the code I am using:

dim ws as Workspace
dim RemoteDB as Database

set ws =DBEngine.Workspaces(0)
set RemoteDB=ws.OpenDatabase("c:\MyDB.mdb",,True)

The last statement gives me an error only when, and always
when I am trying to open a read-only database.

Thanks in advance for any help.
 
D

Dirk Goldgar

Margaret Bartley said:
DAO 3.6 Access 2000:

Whenever I try to open a database that is read-only, I get
the error 3051 - that I cannot open the file because it is
opened exclusively by another user, or I don't have
permission to read it.

I am working on my local machine, and I know it's not opened
by another user, besides, I get this message whenever, and
only, when I try to open a read-only file. None of these
files have any security on them. I can open them through
the user interface.

This is the code I am using:

dim ws as Workspace
dim RemoteDB as Database

set ws =DBEngine.Workspaces(0)
set RemoteDB=ws.OpenDatabase("c:\MyDB.mdb",,True)

The last statement gives me an error only when, and always
when I am trying to open a read-only database.

Thanks in advance for any help.

I'm not sure why, but I find that I can do it if I also specify that I'm
opening the database exclusively:

Set db = ws.OpenDatabase("Cc:\MyDB.mdb", True, True)
 
D

Douglas J. Steele

Dirk Goldgar said:
I'm not sure why, but I find that I can do it if I also specify that I'm
opening the database exclusively:

Set db = ws.OpenDatabase("Cc:\MyDB.mdb", True, True)

Actually, I don't think it matters whether you're opening it exclusively or
not. What does matter is that you've supplied a value for the 2nd parameter.
My understanding is that Access ignores all parameters after the first
missed one in the OpenDatabase statement (even though they're marked as
optional)

It should also work (although I haven't test it) using

Set db = ws.OpenDatabase(Name:="C:\MyDB.mdb", ReadOnly:=True)
 
D

Dirk Goldgar

Douglas J. Steele said:
Actually, I don't think it matters whether you're opening it
exclusively or not. What does matter is that you've supplied a value
for the 2nd parameter. My understanding is that Access ignores all
parameters after the first missed one in the OpenDatabase statement
(even though they're marked as optional)

It should also work (although I haven't test it) using

Set db = ws.OpenDatabase(Name:="C:\MyDB.mdb", ReadOnly:=True)

I'd forgotten about that, Doug. You're right about what the problem is,
though for some reason your suggested line doesn't work (at least, not
for me). I can't see why not, but it doesn't. Either of these does,
though:

Set db = ws.OpenDatabase("C:\MyDB.mdb", True, True)
Set db = ws.OpenDatabase("C:\MyDB.mdb", False, True)

Thanks for pointing out the real source of the problem.
 
D

Douglas J. Steele

Dirk Goldgar said:
I'd forgotten about that, Doug. You're right about what the problem is,
though for some reason your suggested line doesn't work (at least, not
for me). I can't see why not, but it doesn't. Either of these does,
though:

Set db = ws.OpenDatabase("C:\MyDB.mdb", True, True)
Set db = ws.OpenDatabase("C:\MyDB.mdb", False, True)

Thanks for pointing out the real source of the problem.

Well, I _did_ warn you it was untested! <g>

It may well be that the names of the parameters aren't actually Name and
ReadOnly (even though that's what they are in the Object Browser and in
through Intellisense). To be honest, though, I always do it the same as you:
it's less typing!
 
M

Margaret Bartley

Thanks, guys, that worked. After ten years, I'm still
finding little "gotchas". I
mentioned this to a group of developers I network with on an
informal basis,
and everyone else was surprised, as well.


"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com>
wrote in message
 

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