Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-16
8
Medium Priority
?
849 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 1500 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 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