Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server Azure Automation中用于运行SQL Server存储过程的Powershell脚本-可能存在超时问题_Sql Server_Powershell_Azure Automation - Fatal编程技术网

Sql server Azure Automation中用于运行SQL Server存储过程的Powershell脚本-可能存在超时问题

Sql server Azure Automation中用于运行SQL Server存储过程的Powershell脚本-可能存在超时问题,sql-server,powershell,azure-automation,Sql Server,Powershell,Azure Automation,我们使用Azure自动化按计划执行Azure SQL Server存储过程 以下是其中一个脚本: workflow ExecuteSP1 { Write-Output "JOB START BEFORE INLINESCRIPT" inlinescript { Write-Output "JOB START" # Create connection to Master DB $MasterDatabaseConnectio

我们使用Azure自动化按计划执行Azure SQL Server存储过程

以下是其中一个脚本:

workflow ExecuteSP1
{
    Write-Output "JOB START BEFORE INLINESCRIPT"

    inlinescript
    {
        Write-Output "JOB START"
        # Create connection to Master DB
        $MasterDatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
        $MasterDatabaseConnection.ConnectionString = "Connection String"
        $MasterDatabaseConnection.Open()

        Write-Output "CONNECTION OPEN"

        # Create command
        $MasterDatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
        $MasterDatabaseCommand.Connection = $MasterDatabaseConnection
        $MasterDatabaseCommand.CommandText = "dbo.StoredProcedure1"

        Write-Output "DATABASE COMMAND TEXT ASSIGNED"

        # Execute the query
        $MasterDatabaseCommand.ExecuteNonQuery()

        Write-Output "EXECUTING QUERY"

        # Close connection to Master DB
        $MasterDatabaseConnection.Close() 

        Write-Output "CONNECTION CLOSED"
    }    
    Write-Output "WORK END - AFTER INLINESCRIPT"
在检查成功日志时,Azure Automation每次都会通知我们此脚本已成功运行。但是,SQL Server中产生的影响并没有反映为已经发生。所以我只能想象这意味着存储过程正在超时。我已经确认,当我直接在SQL Server上运行SP时,它运行正常,但运行确实需要很长时间

我是否可以在上述脚本中添加以下内容:

  • 在脚本中或SQL Server端,是否将任何超时时间增加到无限长或至少4小时

  • 如果存储过程没有成功地完成执行,是否会在AA中抛出错误


  • 你可以做几件事。首先,您可以指定您的:

    接下来,您可以使用try-catch,尽管我不确定Azure Automation将如何处理它:

    try {
      # Execute the query
      $MasterDatabaseCommand.ExecuteNonQuery()
    
      Write-Output "EXECUTING QUERY"
    }
    catch {
      Write-Error $Error[0].Exception.Message
      # or write to your log file or do what you need to here
    }
    

    只需将超时0添加到连接字符串
    try {
      # Execute the query
      $MasterDatabaseCommand.ExecuteNonQuery()
    
      Write-Output "EXECUTING QUERY"
    }
    catch {
      Write-Error $Error[0].Exception.Message
      # or write to your log file or do what you need to here
    }