I need to get the metadata of some hundred MS Access DBs, so I need to automate the process of metadata gathering.
I want to query stuff described here, but before I can query the DBs I need read access to MSysObjects
tables.
I Keep getting following error:
Record(s) cannot be read; no read permission on 'MsysObjects'.
so I dug deeper:
I've read the article about similar issues in the C# section (see here and also this one).
I put together a simple script which works well for creating tables and so on, but I am having problems to setup the read access.
$ScrUsr = $(whoami)
Write-Host $ScrUsr
$cmd = "GRANT SELECT ON MSysObjects TO [$ScrUsr]"
Write-Host $cmd
Function Invoke-ADOCommand($Db)
{
$connection = New-Object -ComObject ADODB.Connection
$connection.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$db;" )
$command = New-Object -ComObject ADODB.Command
$command.ActiveConnection = $connection
$command.CommandText = $cmd
$rs = $command.Execute()
$connection.Close()
}
$Db = "C:\Temp\test1.accdb"
Invoke-ADOCommand -db $Db
Executing the Script throws me following Error reason:
Cannot open the Microsoft Office Access database engine workgroup information file.
How can I allow read permission on MSysObjects
?