Solved

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

Posted on 2004-09-16
8
752 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
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
 
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now