Run C# queries against (hidden) system tables in Access?

跟風遠走 提交于 2019-12-11 08:43:34

问题


I'm trying to run the following query against an Access 2007 database in C#:

OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "SELECT * FROM MSysQueries";
OleDbDataReader reader = command.ExecuteReader();

And I get the error:

Record(s) cannot be read; no read permission on 'MSysQueries'.

Is it possible to do this? If so how? I am under the impression it is possible to do this but I'm not completely sure.


回答1:


As mentioned in the similar question here, to get around the

Record(s) cannot be read; no read permission on 'MSysQueries'.

error you need to GRANT SELECT privileges to the default user "Admin" with the command

GRANT SELECT ON MSysQueries TO Admin

You can execute that SQL statement from a .NET OleDbConnection, but in order to do so you need to specify the location of the default Workgroup Information File (System.mdw) in your connection string like this:

myConnectionString =
        @"Provider=Microsoft.ACE.OLEDB.12.0;" +
        @"Data Source=C:\Users\Public\Database1.accdb;" +
        @"Jet OLEDB:System database=C:\Users\Gord\AppData\Roaming\Microsoft\Access\System.mdw;";

That path to the .mdw file can be retrieved from the Windows registry by reading the value

Key:
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Access Connectivity Engine\Engines

Value:
SystemDB

(The value 14.0 in the above key is for Access 2010. Other versions of Access will have different values.)




回答2:


You can give access to you doing this in the Access 2007:

Tools Menu -> Security -> User and Group Permissions. Give 'Read Data' permission to the Admin user on MSysObjects table.

But you have to be sure that the MSysObjects isn't locked in purpose for security reasons.



来源:https://stackoverflow.com/questions/23625427/run-c-sharp-queries-against-hidden-system-tables-in-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!