Trying to read data out of MSysObjects with ODbc in C#, but getting no permission error

好久不见. 提交于 2019-12-13 13:53:20

问题


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.

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

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

Connection String:

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

This is the standard Connection Sting as seen on http://www.connectionstrings.com/access/

How can I get access to read from MSysObjects ?


回答1:


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.

Execute a DDL GRANT statement to give Admin that permission.

GRANT SELECT ON MSysObjects TO Admin;

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

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'."

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



来源:https://stackoverflow.com/questions/18121099/trying-to-read-data-out-of-msysobjects-with-odbc-in-c-but-getting-no-permissio

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