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

I wrote a script to download mdb files and read them due to the OLEDB provider. Everything works fine, but if I try to read from a table this throws an exception:

Access to Ms: record (s) cannot be read; no read permission for tblMytable

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

I changed the permissions directly in Ms Access for the user "administrator" and it works. But the problem is that this musst script runs twice a day and it downloads about 20 files. Therefore, it is not possible to manually change permissions.

Can I programmatically change read permissions for a table?

Thanks so much for any ideas!

+6
source share
1 answer

I solved this using the system.mdw file. I copied this file from "c: \ Users \ Administrator \ AppData \ Roaming \ Microsoft \ Access \" (in Win7) to the application directory (App_Data) and the 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 it is still not possible to read the data, I issue the grant command:

 "GRANT SELECT ON TABLE tblTable TO PUBLIC" 

And it works :)

+5
source

Source: https://habr.com/ru/post/908890/


All Articles