How can I access a linked table in Access when using PowerShell?
I have a .mdb database, within which is a linked table to an external CSV file. When using Access, all works well - I can open the table with no problems, and perform SQL queries on the contents.
However, I am now trying to automate the initial data-load using PowerShell (since VBScript is now deprecated), using the following method:
$adOpenStatic = 3
$adLockOptimistic = 3
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$objConnection.Open("
Provider = Microsoft.ACE.OLEDB.12.0;
Data Source = C:\Data\My_Frontend.mdb
")
$objRecordset.Open(
"Select * from Linked_Table",
$objConnection,$adOpenStatic,$adLockOptimistic)
$objRecordset.MoveFirst()
do {
$objRecordset.Fields.Item("product").Value;
$objRecordset.MoveNext()
} until ($objRecordset.EOF -eq $True)
$objRecordset.Close()
$objConnection.Close()
If I query an ordinary table from within PowerShell, everything works fine. If, however, I try and pull data from the linked table, I get the error:
The text file specification 'Patient-orders Link Specification' does not exist. You cannot import, export, or link using the specification.
What is confusing me is that I do have a link specification saved, and being used to link/import the data. Therefore:
- Why am I getting this error;
- more importantly, how do I fix this?
Thank you!