Solved

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

Posted on 2004-09-16
8
735 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
  • 3
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:pique_tech
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 12

Expert Comment

by:pique_tech
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:DMV
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now