我对天蓝色运行手册和自动化很陌生。
我有几个 azure Sql 数据库,并且我想按顺序运行数据库中的存储过程。在本地 SQL Server 之前,我们有一个 SQL 作业代理来按顺序运行存储过程。做一些研究,看起来 SQL 作业代理已被 Azure 自动化取代。
现在我想创建一个运行手册,它可以接受参数来一个一个地运行存储过程。然后通过提供参数来运行每个存储过程,创建另一个 Runbook 来调用子 Runbook。
我在这里找到了一个脚本,它允许我从 Runbook 运行存储过程。
这是运行手册脚本:
workflow SQL_Agent_SprocJob
{
[cmdletbinding()]
param
(
# Fully-qualified name of the Azure DB server
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $SqlServerName,
# Name of database to connect and execute against
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $DBName,
# Name of stored procedure to be executed
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $StoredProcName,
# Credentials for $SqlServerName stored as an Azure Automation credential asset
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[PSCredential] $Credential
)
inlinescript
{
Write-Output “JOB STARTING”
# Setup variables
$ServerName = $Using:SqlServerName
$UserId = $Using:Credential.UserName
$Password = ($Using:Credential).GetNetworkCredential().Password
$DB = $Using:DBName
$SP = $Using:StoredProcName
# Create & Open connection to Database
$DatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
$DatabaseConnection.ConnectionString = “Data Source = $ServerName; Initial Catalog = $DB; User ID = $UserId; Password = $Password;”
$DatabaseConnection.Open();
Write-Output “CONNECTION OPENED”
# Create & Define command and query text
$DatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
$DatabaseCommand.CommandType = [System.Data.CommandType]::StoredProcedure
$DatabaseCommand.Connection = $DatabaseConnection
$DatabaseCommand.CommandText = $SP
Write-Output “EXECUTING QUERY”
# Execute the query
$DatabaseCommand.ExecuteNonQuery()
# Close connection to DB
$DatabaseConnection.Close()
Write-Output “CONNECTION CLOSED”
Write-Output “JOB COMPLETED”
}
}
然后我想创建另一个运行手册并调用“SQL_Agent_SprocJob”子运行手册来传递参数。
这是我的父母手册:
workflow HelloWorldStoredProcedure
{
$SqlServerName = "mydbserver.database.windows.net"
Write-Output $SqlServerName
SQL_Agent_SprocJob -SqlServerName $SqlServerName -Credential "myCredentialName" -DBName "myDbName" -StoredProcName "dbo.HelloWorld"
Write-Output "Complete!"
}
当我运行此运行手册时,运行手册失败并显示以下消息:
嵌套工作流不支持高级参数验证
在此链接中,他们展示了这是运行嵌套运行手册的方式:
知道问题出在哪里吗?