So, I have the following script (thanks to JRV!):
function Link-ExternalODBCTable{
Param(
$accessFile,
$tableName,
$tableName2
)
if(-not $tableName2){$tableName2=$tableName1}
$access.DoCmd.TransferDatabase(
[microsoft.office.interop.access.AcDataTransferType]::acLink,
'ODBC Database',
$accessFile,
[microsoft.office.interop.access.AcObjectType]::acTable,
$tableName,
$tableName2
)
}
$testODBC='ODBC;DSN=A1013v2012'
Add-Type -Assembly Microsoft.Office.Interop.Access
$access = New-Object -ComObject Access.Application
$Access.OpenCurrentDataBase("E:\MyDir\TagLink.mdb")
Link-ExternalODBCTable $testODBC all_per
$access.CloseCurrentDataBase()
What I get is:
Exception calling "TransferDatabase" with "6" argument(s): "ODBC--connection to 'A1013v2012' failed."
When I try from the ODBC Administrator, it tests fine (Connection Successful!). This is a 32-bit ODBC connection, using the Pervasive ODBC Engine Interface. Same as we use for other ODBC connections to this database. It is a System DSN, as opposed to User or File.
I tried to skinny this down to:
Add-Type -Assembly Microsoft.Office.Interop.Access
$Access = New-Object -ComObject Access.Application
$Connected = $Access.OpenCurrentDataBase("E:\MyDir\TagLink.mdb")
$access.DoCmd.TransferDatabase(
[microsoft.office.interop.access.AcDataTransferType]::acLink,
'ODBC Database',
'ODBC;DSN=A1013v2012',
[microsoft.office.interop.access.AcObjectType]::acTable,
'all_per',
'all_per'
)
$Disconnected = $Access.CloseCurrentDataBase()
...which yields the same error.
Where am I going wrong here?
mpleaf