开发者

Is ADO unable to report a database is marked read-only?

If "read only" is checked in the Windows desktop properties for a .dbf or .mdb file, and a Delphi 6 ADO connection (say, via Jet for an .mdb file or ODBC for a .dbf开发者_开发问答 file) is then used to open that database, TADOTable.CanModify returns true and TADOTable.ReadOnly returns false, apparently failing to detect the file is actually read-only.

From the VCL source, it looks like .CanModify is just set from Supports(xUpdates) and .ReadOnly is set from the LockType (even "read-only data source" in TADOConnection.Properties returns 0), so those properties seem more like tools for detecting connectionstring options as opposed to detecting the database's original read-only state.

So what's the proper ADO technique to detect a database is marked read-only before TADOTable.Edit is attempted? Seems the solution should not be specific to Windows files, but some kind of database-independent technique using just ADO. What's the solution?


I know the question is old, but it seems the accepted answer is at least incomplete. From my own experiments it seems you can detect a read-only database prior to attempting to edit data:

My setup:

I create a TADOConnection to a MDB file using the following ConnectionString: Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\SomePath\MyDatabase.mdb"; I use a few more flags but they don't seem to matter here.

Normally when connecting, MyADOConnection.Mode switches from cmUnknown to cmShareDenyNone.

My observation:

When C:\SomePath\MyDatabase.mdb file is marked as read-only by the operating system, the connection's Mode property switches to cmRead instead upon connecting.

I can access this property directly from my TADODataset through MyDataset.Connection.Mode

Side note: In my experiments, subsequent connections required Mode to be reset to cmUnknown in order for it to be able to switch back properly to cmShareDenyNone.

Please also note that editing a row may still fail for various other reasons, even if Mode returns cmShareDenyNone. This does, however solve the original question, as to how to detect a MDB that is marked as "read-only" by the OS.


It's a pity, but you can't.

However, since the filename is part of the connection string, you can check yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜