Microsoft KB Archive/195475

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

Article ID: 195475

Article Last Modified on 10/15/2003

-

APPLIES TO


 * Microsoft OLE DB Provider for Jet 3.51, when used with:
 * Microsoft Data Access Components 2.0

-



This article was previously published under Q195475



SYMPTOMS
Opening the connection on a read-only Microsoft Access Database (.mdb file on a CD-ROM, a floppy disk that is write protected, or a hard disk that is read-only to the user, and so forth) with the following code causes an error to occur. The following code opens a connection on a Microsoft Access database 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.



CAUSE
The Jet OLEDB provider opens databases, by default, in Read/Write mode. Jet requires the creation of a locking file (.ldb file) in order to open a database file in shared access mode. If you request shared access mode, Jet attempts to create the locking file, which fails on read-only media. If you open a database using exclusive mode, Jet does not need to create the locking file.



RESOLUTION
Open the database in read-only and exclusive mode. You can do this by setting the Mode property of the connection object to adShareDenyWrite.

The following code opens a connection on a read-only Microsoft Access database: Dim con as new ADODB.Connection con.Provider = "Microsoft.Jet.Oledb.3.51" con.Mode = adShareDenyWrite con.Open "Data Source=E:\testdb.mdb"

