Ms Access: Record(s) cannot be read; no read permission on [table]

纵饮孤独 提交于 2019-12-07 00:14:59

问题


i wrote script for downloading mdb files and reading them due OLEDB provider. All works fine, but if i try to read from table, it throws an exception:

Ms Access: Record(s) cannot be read; no read permission on tblMytable

 var cmd = new OleDbCommand("SELECT * FROM tblMytable", conn);
 var reader = cmd.ExecuteReader();

I changed permissions directly in Ms Access for user "administrator" and it works. But the problem is, that this script musst run twice a day and it downloads about 20 files. So its impossible manually changing permissions.

Is it possible to change read rights for a table programatically?

Thanks a lot for any ideas!


回答1:


I solved this by using system.mdw file. I copied this file from "c:\Users\Administrator\AppData\Roaming\Microsoft\Access\" (in Win7) to application directory (App_Data) and modified connection string.

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Database.MDB;Persist Security Info=True;Jet OLEDB:System Database=|DataDirectory|\System.MDW;

var conn = new OleDbConnection(connectionString);

If still it's impossible to read data, i execute grant command:

"GRANT SELECT ON TABLE tblTable TO PUBLIC"

And it works :)



来源:https://stackoverflow.com/questions/9361259/ms-access-records-cannot-be-read-no-read-permission-on-table

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