Advantage Database connection string in Powershell

108 Views Asked by At

Does anyone know the right format of the connection string required to connect to the Advantage Database in PowerShell? what even is the driver that needs to be used?

I cant even find any documentation relating to the advantage database, so if anyone has a link to that, I would be very grateful.

EDIT:

I have this code now:

$connectionString = "Driver={Advantage ODBC Driver};Data Source=xxx;"
$connection = New-Object System.Data.Odbc.OdbcConnection
$connection.ConnectionString = $connectionString
$connection.Open()

and it produces this error:

[14:45] Greg Skrzypczak
Exception calling "Open" with "0" argument(s): "ERROR [08001] [iAnywhere Solutions][Advantage ODBC Driver]Unable to connect"

At line:4 char:1

+ $connection.Open()

+ ~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : OdbcException

I am pretty sure I am missing something or have got something wrong... I know ODBC driver is set up correctly as other services use it without a hickup...

2

There are 2 best solutions below

0
Gregory Sky On BEST ANSWER

solved it, posting solution as it might help others:

instead of 3 lines of code all is needed, before opening connection, is:

$connection = New-Object System.Data.Odbc.OdbcConnection("DSN=NameOfDSNiWantToUSe")
1
weshouman On

For ODBC you could try with

$connectionString = "Driver={Advantage ODBC Driver};Data Source=myServerAddress;Catalog=myDataBase;User=myUsername;Password=myPassword;"
$connection = New-Object System.Data.Odbc.OdbcConnection
$connection.ConnectionString = $connectionString
$connection.Open()

# Perform database operations

$connection.Close()

Or for OLE DB

$connectionString = "Provider=Advantage.OLEDB;Data Source=myServerAddress;Catalog=myDataBase;User ID=myUsername;Password=myPassword;"
$connection = New-Object System.Data.OleDb.OleDbConnection
$connection.ConnectionString = $connectionString
$connection.Open()

# Perform database operations

$connection.Close()