Getting an System.Data.Odbc.OdbcException: when I run a script natively in PowerShell 5 (on Win10 and Server 2k12r2), however if I run the same script in Visual Studio 2015 Enterprise with PowerShell Tools for VS2015 v3.0.323 installed it runs fine and no
errors or exceptions.
Any help would be greatly appreciated.
PSVersion 5.0.10586.63
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.63
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Query I'm running:
$IBIConnection = New-Object System.Data.Odbc.OdbcConnection
$IBIConnection.ConnectionString = "DSN=iBI DaaS;Uid=myUsername;Pwd=;"
$IBIOdbcCmd = New-Object system.Data.Odbc.OdbcCommand
$IBIAllSQLQuery = "select [id] as [Feature]
, [[title] as [Description]
, [bugeco.fixed] as [Fixed]
from [ES.bugeco]
where ([release] like ( '%YYZ' ) or [ES.bugeco].[release_affected] like ( '%YYZ' ) )
and [id] in ( 12345, 123456 )
order by [id] asc"
# Init Table
If ($IBIDataTable -ne $null)
{
$IBIDataTable.Clear()
$IBIDataTable.Dispose()
Write-Host "Clearing DataTable"
}
$IBIDataTable = New-Object system.Data.DataTable "Bug_Table"
$FeatureCol = New-Object System.Data.DataColumn Feature,([int32])
$DescriptionCol = New-Object System.Data.DataColumn Description,([string])
$FixedCol = New-Object System.Data.DataColumn Fixed,([string])
$IBIDataTable.Columns.Add($FeatureCol)
$IBIDataTable.Columns.Add($DescriptionCol)
$IBIDataTable.Columns.Add($FixedCol)
# Connect to SQL
$IBIConnection.open()
$IBIOdbcCmd.CommandText = $IBIAllSQLQuery
$OdbcAdapter = New-Object system.Data.Odbc.OdbcDataAdapter
$OdbcAdapter.SelectCommand = $IBIOdbcCmd
$IBIOdbcCmd.Connection = $IBIConnection
# Fill Table with SQL Data
[void]$OdbcAdapter.Fill($IBIDataTable)
# Close SQL Connection
$IBIConnection.close()
Exception Thrown:
Exception : System.Management.Automation.MethodInvocationException: Exception calling "Fill" with "1" argument(s): "ERROR [HY000] The request was invalid or
the request is without authentication or cannot be otherwise served." --->
System.Data.Odbc.OdbcException: ERROR [HY000] The request was invalid or the request is without authentication or cannot
be otherwise served.
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean
needReader, Object[] methodArguments, SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean
needReader)
at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords,
IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at CallSite.Target(Closure , CallSite , Object , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext,
Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject :
CategoryInfo : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : OdbcException
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, F:\Workspaces\Visual Studio 2015\Projects\PowerShellProjects\PowerShellProjects\psScripts\HSD_ES Test.ps1: line 55
PipelineIterationInfo : {}
PSMessageDetails :