Runbook Azure Запуск нескольких запросов SQL параллельно

Можно ли запустить несколько команд SQL-сервера параллельно из среды выполнения Azure? Я хотел бы запустить 5-10 хранимых процедур одновременно для обработки данных, размещенных в ASQLDB:

Локально, найденные / показанные ниже фрагменты кода работают нормально: a Start-Job $scriptBlock -ArgumentList запускает несколько соединений sql и выполняет SP для каждого входного параметра:

$ExecutionContext.SessionState.LanguageMode

#Various parameters to differentiate upon 
'NEW_TX', 'NEW_CUST'| %{ 
    echo  $_
    $scriptBlock = { 
        param($serviceName) 

# Get & set Azure variables
 Write-Output "Step1-connecting to  Azure env." 
 # Connect to a connection to get TenantId and SubscriptionId
$Connection =       Get-AutomationConnection -Name "AzureRunAsConnection"
$TenantId =         $Connection.TenantId
$SubscriptionId =   $Connection.SubscriptionId
$null =             $SqlCredential = Get-AutomationPSCredential -Name "someusr"

$SqlUsername =      $SqlCredential.UserName 
$SqlPass =          $SqlCredential.GetNetworkCredential().Password 
$SqlServer=         "abcdefg.database.windows.net"
$Database =         "db"
$SqlServerPort =    "1433"

# local db (for local testing, which is all okay in parallel...)
#$SqlCredential=    "noop"
#$SqlServer=    "SQL2017EE-LT"
#$Database =    "DWH"
#$SqlUsername =     "dbusername"
#$SqlPass =     "JustanotherPassword"
$Table =        "[dbo].[dwh_fct_Trns]"

 Write-Output "Step2-connecting to SQL." 
    $Conn=New-Object System.Data.SqlClient.SqlConnection("Server=tcp:$SqlServer,$SqlServerPort;Database=$Database;User ID=$SqlUsername;Password=$SqlPass;Connection Timeout=30;") 

    $Conn.Open() 

        Write-Output "Executing SQL statement with a time-out of 10 minutes."  
        #$Cmd=new-object system.Data.SqlClient.SqlCommand("SELECT COUNT(*) from $Table", $Conn) 
         $Cmd=new-object system.Data.SqlClient.SqlCommand("EXEC [dbo].[From_staging_to_dwh] '$ServiceName'",$Conn)
             $Cmd.CommandTimeout=600

        # Execute the SQL command 
        $Ds=New-Object system.Data.DataSet 
        $Da=New-Object system.Data.SqlClient.SqlDataAdapter($Cmd) 

            try {
            $result= $Da.fill($Ds)  
                } catch { 
                    Write-Host "Error: " $_.Exception.Message ,$e.Exception.Response
                    throw "Error while executing command. Now Exiting."
               }

            Write-Output "Result: $Result" 
            # Output the count  
            $Ds.Tables.Column0

    # Close the SQL connection 
    $Conn.Close()       
    }

Start-Job $scriptBlock -ArgumentList $_ 
}
# Wait for it all to complete, poll every 2 seconds

While (Get-Job -State "Running") 
    { 
       Start-Sleep 2
       echo '--------------------------------------------------------------------------------------------------------------' 
        Get-Job 
    }

# Getting the information back from the jobs 
Get-Job | Receive-Job
Remove-Job *

Сообщение об ошибке при выполнении из Runbook Azure:

Step1-connecting to  Azure env.
Step2-connecting to SQL.

Cannot create type. Only core types are supported in this language mode.

    + CategoryInfo          : PermissionDenied: (:) [New-Object], PSNotSupportedException

    + FullyQualifiedErrorId : CannotCreateTypeConstrainedLanguage,Microsoft.PowerShell.Commands.NewObjectCommand

    + PSComputerName        : localhost

You cannot call a method on a null-valued expression.

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
   + PSComputerName        : localhost

 Executing SQL statement with a time-out of 10 minutes.

или любой другой подход тоже приветствуется! Спасибо..!

0 ответов

Другие вопросы по тегам