尝试在C#中使用ODbc从MSysObjects中读取数据,但没有获得权限错误 [英] Trying to read data out of MSysObjects with ODbc in C#, but getting no permission error

查看:268
本文介绍了尝试在C#中使用ODbc从MSysObjects中读取数据,但没有获得权限错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题中所述: 我正在尝试从Access 2010数据库中的MSysObjects中读取数据,但是出现一个异常告诉我不允许从该表中读取数据.

As described in the title: I am trying to read out data from MSysObjects in a Access 2010 database, but I get an exception telling me I am not allowed to read from that table.

我可以读出其他非MSys表.

I can read out of the other non-MSys Tables.

SQL Query I am using: SELECT * FROM MSysObjects WHERE Type=1 AND Flags=0

连接字符串:

Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;Uid=Admin;Pwd=;

这是在 http://www.connectionstrings.com/access/

如何获得从MSysObjects读取的权限?

How can I get access to read from MSysObjects ?

推荐答案

由于您的数据库是ACCDB格式,这意味着数据库引擎将 Admin 视为运行所有查询的用户.并且 Admin 没有对MSysObjects的读取(SELECT)权限.

Since your db is ACCDB format, that means the db engine sees Admin as the user who runs all your queries. And Admin does not have read (SELECT) permission for MSysObjects.

执行DDL GRANT语句以授予 Admin 权限.

Execute a DDL GRANT statement to give Admin that permission.

GRANT SELECT ON MSysObjects TO Admin;

我不确定该语句可以从ODBC连接执行.如果失败,请在Access应用程序会话中打开该数据库,然后在该数据库中运行.

I'm not certain that statement can be executed from an ODBC connection. If it fails, open the db in an Access application session and run it there.

CurrentProject.Connection.Execute "GRANT SELECT ON MSysObjects TO Admin;"

请注意,必须从ADO执行语句 . CurrentProject.Connection是ADO对象,因此其Execute方法可以成功运行该语句.如果您尝试使用某些基于DAO的方法,例如CurrentDb.Execute或在查询设计器中将该语句作为查询运行,它将失败并显示错误3129,无效的SQL语句;预期为'DELETE','INSERT ','PROCEDURE','SELECT'或'UPDATE'."

Note that statement must be executed from ADO. CurrentProject.Connection is an ADO object, so its Execute method can run the statement successfully. If you try to use some DAO-based method, such as CurrentDb.Execute or run the statement as a query in the query designer, it will fail with error 3129, "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'."

或者,如果您是通过OleDb连接到Access db来运行它,那么它应该可以在c#中工作.

Alternatively, it should work from c# if you run it from an OleDb connection to the Access db.

这篇关于尝试在C#中使用ODbc从MSysObjects中读取数据,但没有获得权限错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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