2

I'm trying to run the following query against an Access 2007 database in C#:

OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "SELECT * FROM MSysQueries";
OleDbDataReader reader = command.ExecuteReader();

And I get the error:

Record(s) cannot be read; no read permission on 'MSysQueries'.

Is it possible to do this? If so how? I am under the impression it is possible to do this but I'm not completely sure.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Ben
  • 2,518
  • 4
  • 18
  • 31
  • There is a similar question [here](http://stackoverflow.com/q/19971082/2144390). Does its answer help? – Gord Thompson May 13 '14 at 11:16
  • It is the same problem but I cant seem to get that solution to work. – Ben May 14 '14 at 14:43
  • Did you follow the instructions [here](http://stackoverflow.com/a/19971579/2144390) to execute `GRANT SELECT ON MSysQueries TO Admin`? I just tried it and it worked for me. – Gord Thompson May 14 '14 at 15:31

2 Answers2

6

As mentioned in the similar question here, to get around the

Record(s) cannot be read; no read permission on 'MSysQueries'.

error you need to GRANT SELECT privileges to the default user "Admin" with the command

GRANT SELECT ON MSysQueries TO Admin

You can execute that SQL statement from a .NET OleDbConnection, but in order to do so you need to specify the location of the default Workgroup Information File (System.mdw) in your connection string like this:

myConnectionString =
        @"Provider=Microsoft.ACE.OLEDB.12.0;" +
        @"Data Source=C:\Users\Public\Database1.accdb;" +
        @"Jet OLEDB:System database=C:\Users\Gord\AppData\Roaming\Microsoft\Access\System.mdw;";

That path to the .mdw file can be retrieved from the Windows registry by reading the value

Key:
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Access Connectivity Engine\Engines

Value:
SystemDB

(The value 14.0 in the above key is for Access 2010. Other versions of Access will have different values.)

Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • I knew this was the gist of the process from the other question but for the life of me I could not follow the other answers. This was very easy to follow and concise thank you. – Ben May 15 '14 at 07:33
  • I agree, good answer. Access 2007 is ...\Office\12.0\Access\.... I think Access 2003 is 8.0 – FreeText Apr 26 '16 at 23:33
  • Thank you Gord! I wish I would have seen this sooner, would have saved me an hour of googling "Cannot open the Microsoft Access database engine workgroup information file". – Mitch Stewart Aug 31 '16 at 16:41
0

You can give access to you doing this in the Access 2007:

Tools Menu -> Security -> User and Group Permissions. Give 'Read Data' permission to the Admin user on MSysObjects table.

But you have to be sure that the MSysObjects isn't locked in purpose for security reasons.

Thanos Markou
  • 2,587
  • 3
  • 25
  • 32
  • I'm actually in Access 2010 and I cant find a Tools menu? – Ben May 13 '14 at 07:53
  • The Tools menu seems to be visible only for .mdb files. See similar question referenced in another answer. ([link](http://stackoverflow.com/questions/19971082/no-read-permission-on-msysobjects)) – FreeText Apr 26 '16 at 23:13