Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell to create link between Access database and an ODBC Pervasive database

$
0
0

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


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>