对Access中的(隐藏)系统表运行C#查询? [英] Run C# queries against (hidden) system tables in Access?

查看:73
本文介绍了对Access中的(隐藏)系统表运行C#查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对C#中的Access 2007数据库运行以下查询:

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();

我得到了错误:

无法读取记录;没有对"MSysQueries"的读取权限.

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.

推荐答案

如在类似问题此处所述,绕过

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

无法读取记录;没有对"MSysQueries"的读取权限.

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

错误,您需要使用命令将默认用户"Admin"的SELECT权限授予

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

GRANT SELECT ON MSysQueries TO Admin

您可以从.NET OleDbConnection执行该SQL语句,但是为此,您需要在连接字符串中指定默认工作组信息文件(System.mdw)的位置,如下所示:

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;";

可以通过读取值从Windows注册表中检索.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

(上面键中的值14.0用于Access2010.其他版本的Access将具有不同的值.)

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

这篇关于对Access中的(隐藏)系统表运行C#查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆