Querying AcuXDBC from PowerShell

I am trying to query AcuXDBC from PowerShell.

Here is the PowerShell script:

$SqlCommand = "select * from kund;"

$conn = new-object System.Data.Odbc.OdbcConnection
$conn.connectionstring = "DSN=acuxdbc"
$conn.open()

$cmd = New-object System.Data.Odbc.OdbcCommand($sqlCommand,$conn)
$dataset = New-Object System.Data.DataSet
$results = (New-Object System.Data.Odbc.OdbcDataAdapter($cmd)).Fill($dataSet)
Write-Output $results
$conn.Close()

But I get this error:

Exception calling "Fill" with "1" argument(s): "ERROR [HY000] [TOD][ODBC][GENESIS](pos: 19 '... * from kund^;') - syntax error"

The same query from odbcsql runs ok.

Any ideas?

  • Verified Answer

    You do not need the semicolon (;) at the end. The error message is indicating this with the ^. The semicolon is only needed when you have several statements concatenated, but if that was the case, which rowset would be returned to your query? ODBC is a single SQL statement at a time and AcuXDBC does not support a terminating semicolon on its statements, and why should it? If you look at the syntax for the SELECT statement, the semicolon is not in the formal definition.

    Next time you get a syntax error, look for the ^ in the error message. It is indicating the last location that parsing of the statement was successful. Immediately after that is usually the syntax error.

  • This is great feedback! I guess the semicolon used in odbcsql confused me.

    Thank you very much!