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

1

8

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!

Seclude answered 20/2, 2012 at 12:39 Comment(1)
Not sure if you CAN change the rights, but if possible, it will require that you log into db as a user with Admins or Owner permission. So I would suggest that instead you try to directly login as such a user, perhaps by changing you connection string. i suspect that you will need the .MDW file for that.Rolanda
S
8

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 :)

Seclude answered 28/2, 2012 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.