Home > Net >  InterSystems ODBC error crashes Powershell
InterSystems ODBC error crashes Powershell

Time:02-12

I'm trying to take some data through InterSystems ODBC driver with Powershell, but there is an error from the query execution (01004 "String data, right-truncated"). I want to ignore that (or handle this error in PS) and keep the script moving on. Here is the part of my code:

$c = new-object system.data.odbc.odbcconnection
$c.connectionstring = "..."
$c.open()

$cmd = New-object System.Data.Odbc.OdbcCommand( $sql , $c )
$dst = New-Object System.Data.DataSet
$oda = New-Object System.Data.Odbc.OdbcDataAdapter( $cmd )
$oda.Fill( $dst )

This works, i.e., doesn't crash and take the data, when I'm running the script with -NoExit parameter, i.e.:

Powershell -NoExit Y:\test.ps1

Otherways, the Powershell crashes, and the console closes. I need to run this script from another script and eventually receive the result. In the end, I want to close the console window (now I invoke it by exit).

I tried the try-catch block, throws, Invoke-Expression in a few ways, functions with return, etc., as far. I searched for a solution to handle such a type of error, but no result.

CodePudding user response:

The solution which worked for me is to invoke:

Powershell "Y:\test.ps1"

instead of:

& "Y:\test.ps1"

or:

Powershell -NoExit "Y:\test.ps1"
  • Related