问题
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