PRB: Must Open MDB on Read-Only Media with adShareDenyWrite

This article was previously published under Q195475
This article has been archived. It is offered "as is" and will no longer be updated.
Opening the connection on a read-only Microsoft Access Database (.mdb fileon a CD-ROM, a floppy disk that is write protected, or a hard disk that isread-only to the user, and so forth) with the following code causes anerror to occur. The following code opens a connection on a Microsoft Accessdatabase file on a CD-ROM:
   Dim con as new ADODB.Connection   con.Provider = "Microsoft.Jet.Oledb.3.51"   con.Open "Data Source=E:\testdb.mdb"				
It causes the following error:
The Microsoft Jet database engine cannot open the file E:\testdb.mdb. It is already opened exclusively by another user, or you need permission to view its data.
The Jet OLEDB provider opens databases, by default, in Read/Write mode. Jetrequires the creation of a locking file (.ldb file) in order to open adatabase file in shared access mode. If you request shared access mode, Jetattempts to create the locking file, which fails on read-only media. If youopen a database using exclusive mode, Jet does not need to create thelocking file.
Open the database in read-only and exclusive mode. You can do this bysetting the Mode property of the connection object to adShareDenyWrite.

The following code opens a connection on a read-only Microsoft Accessdatabase:
   Dim con as new ADODB.Connection   con.Provider = "Microsoft.Jet.Oledb.3.51"   con.Mode = adShareDenyWrite   con.Open "Data Source=E:\testdb.mdb"				
The following Microsoft Knowledge Base article describes the same problemand a resolution when using Data Access Object (DAO):
191737PRB: DAO MDB on Read-Only Media Must Be Opened Exclusively
Microsoft Developer Network Library, Visual Studio 6.0; search on:
Microsoft Data Access SDK

Article ID: 195475 - Last Review: 01/10/2015 11:37:52 - Revision: 2.0

  • Microsoft OLE DB Provider for Jet 3.51
  • kbnosurvey kbarchive kbdatabase kbjet kbprb KB195475