Solved

Can Open Read-only Database Manually, but not via VBA

Posted on 2004-09-16
8
809 Views
Last Modified: 2006-11-17
Hello All,

Trying to access a read-only A2K database via a NT network using VBA. No protection/privilege  problems when I manually open the DB, but I am unable to get beyond an "Could not Lock File" error using VBA.

The DB is read-only and  does not have a password.

I am invoking the following code:

  Dim dbReadOnly As DAO.Database
  ...
  ...
  ...
  Set dbReadOnly = OpenDatabase(strPATH, vbFalse, vbTrue)

Any ideas?

Thanks in advance.

Deb
0
Comment
Question by:DMV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:pique_tech
ID: 12081135
I have tried unsuccessfully to duplicate your problem using the following code:

Public Sub TestOpenDB()

Dim db As DAO.Database
Dim td As DAO.TableDef

Set db = OpenDatabase("C:\MyDBName.mdb", vbFalse, vbTrue)
For Each td In db.TableDefs
    Debug.Print td.Name
Next
db.Close
Set td = Nothing
Set db = Nothing

End Sub

I have had the target database set unrestricted, read-only, exclusive, and default record locking set to all records, yet each time the Immediate window filled with the names of my tables.  Is it possible that the database is set to open with Exclusive access and that someone else has it open?  That's the only possibility that makes any sense to me, though it also occurs to ask whether you have the proper security on the drive/folder where the database is located.

Scratching head.  Hope this helps, or that someone else has more, better ideas.
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12081154
In particular, you'd have to have file create rights in the directory or Access won't be able to create the .ldf file.  However, I'd think you'd have the same problem opening the database manually if that were the case.
0
 

Author Comment

by:DMV
ID: 12081246
Hello pique-tech,

This seems to be a networking issue; I am able to gain access to the database on my local drive as well.  Again, manual access works fine.

Thanks for your efforts.

Deb
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 12

Expert Comment

by:pique_tech
ID: 12081299
Then I'd certainly investigate the security of the folder where the db is located.  Obviously, if Access cannot create the .ldf file (the locking file), it won't be able to get a lock on the database.
0
 

Author Comment

by:DMV
ID: 12081337
Obvious, or not I am simulating a network drive, using a CD-ROM, and it behaves the same as the network drive -- manual access, no problem, VBA ~ zilch.

From this test, the question arises ~ why can I manually access a db on CD-ROM when I most certanly cannot not create the .ldf on that media.

Hopefully, someone else can further enlighten me about this perplexing issue.

Deb
0
 
LVL 2

Accepted Solution

by:
ApK earned 500 total points
ID: 12081392
I have reproduced this.

As mentioned above, if the folder containing the mdb file does not have write permissions, then access can't create the lock file.

Interestingly, if you open the mdb directly from the same folder (still without write permissions), Access does not create the LDB file (cos it can't), but does not give an error.

In other words, using VBA throws an error, using Access application does not.

So why the difference? I don't know.

However, if you change the 'options' argument to True (i.e. 'exclusive mode'), then it works.

Set dbReadOnly = OpenDatabase(strPATH, True, vbTrue)

It would appear that opening in exclusive mode means no LDB is required, and hence no error.

Cheers,
Andrew.
0
 

Author Comment

by:DMV
ID: 12081552
Thanks Andrew.

Actually, whenever I access the DB on the CD-ROM, it creates a default lock file, System.ldb in C:\Program Files\Common Files\System.

Just when I think MS Access can not possibly be more confusing and/or counter intuitive....  

If I understand you correctly ~ I should set the exclusive-access mode to TRUE to inhibit lock file creation, although I want to open the database for share-access.  What is wrong with this picture?

You are absolutely right,  it does work -- I hope someday, if I am very, very  good the Access Gods might just reveal the "why."

Thanks again for your intervention; I am sure I would have spent hours on this issue.

Best wishes,
Deb
0
 
LVL 2

Expert Comment

by:ApK
ID: 12081631
For shared access, the lock file has to be in the same folder (so that everyone can find it in one place - and 'share' it). So that part makes sense.

I don't know why then it would work in the exclusive case (because to be exclusive, you need to prevent others from modifying it, and therefore you need to write a lock file, but in this case you can't write one, ....).

Perhaps when you ask for exclusive+read only and you don't have permission for the folder, you don't really get a real 'exclusive' mode (and others can come along and possibly modify it while you're using it). I imagine this could cause errors for the read-only user (which might happen anyway in proper shared mode).

I assume you'll want to just give write permission for the folder?

Regards,
Andrew.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

729 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