Public/ps1/Sql/Start-LeftConnectJobSql.ps1

function Start-LeftConnectJobSql {                                                                                                                                                  
      param ($taskInformation)

        if (-not $taskInformation.command) {
            return @{
                message= "No command found"
                sucess= $false
            }
        }

        $sqlConfiguration = Get-LeftConnectSqlConfiguration
        $sqlConn = New-Object System.Data.SqlClient.SqlConnection

        $sqlConn.ConnectionString = $sqlConfiguration.connectionString
        $ErrorActionPreference = "Stop"
        try {
            $sqlConn.Open()
            $sqlcmd = $sqlConn.CreateCommand()
            $sqlcmd.Connection = $sqlConn
            $query = $taskInformation.Command

            # if a channel id is specified
            write-host "$taskInformation.ChannelId"
            if ($taskInformation.ChannelId) {
                if (-not $sqlConfiguration.channelId) {
                    return
                }
                elseif (-not $sqlConfiguration.channelId -eq $taskInformation.ChannelId) {
                    return            
                }
        
            }

            $sqlcmd.CommandText = $query
            $sqlresult = $sqlcmd.ExecuteReader()

            $table = new-object System.Data.DataTable
            $table.Load($sqlresult)

            $returnValue = @{
                data=  @($table | select $table.Columns.ColumnName)
                success= $true
            }
        } catch {
            Log("Connection issue with getting the data. $_")
            $returnValue = @{
                message= $Error[0].Exception
                success= $false
            }
        }
        $ErrorActionPreference = "Continue"
        $sqlConn.Close()
        return $returnValue
    }


    $functionsThread = {
    function Start-LeftConnectJobSql {                                                                                                                                                  
      param ( $taskInformation, $sqlConfiguration)

        if (-not $taskInformation.command) {
            return @{
                message= "No command found"
                sucess= $false
            }
        }

        $sqlConn = New-Object System.Data.SqlClient.SqlConnection

        $sqlConn.ConnectionString = $sqlConfiguration.connectionString
        $ErrorActionPreference = "Stop"
        try {
            $sqlConn.Open()
            $sqlcmd = $sqlConn.CreateCommand()
            $sqlcmd.Connection = $sqlConn
            $query = $taskInformation.Command

            # if a channel id is specified
            write-host "$taskInformation.ChannelId"
            if ($taskInformation.ChannelId) {
                if (-not $sqlConfiguration.channelId) {
                    return
                }
                elseif (-not $sqlConfiguration.channelId -eq $taskInformation.ChannelId) {
                    return            
                }
        
            }

            $sqlcmd.CommandText = $query
            $sqlresult = $sqlcmd.ExecuteReader()

            $table = new-object System.Data.DataTable
            $table.Load($sqlresult)

            $returnValue = @{
                data=  @($table | select $table.Columns.ColumnName)
                success= $true
            }
        } catch {
            Log("Connection issue with getting the data. $_")
            $returnValue = @{
                message= $Error[0].Exception
                success= $false
            }
        }
        $ErrorActionPreference = "Continue"
        $sqlConn.Close()
        return $returnValue
    }
}