I am quite new to azure runbooks and automation.
I have several azure Sql databases and there are stored procedures in the databases that I would like to run in a order. Before in On premises SQL Server we had a SQL Job Agent to run the stored procedures in order. Doing some research it looks like SQL Job agent are replaced with Azure Automation.
Now I would like to create a runbook that would accept parameters to run stored procedures one by one. Then create another runbook to call child runbook by providing parameters to run each stored procedures.
I found a script here that allows me to run stored procedures from a Runbook.
here is the runbook script:
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”
}
}
Then I would like to create another runbook and call the child runbook which is "SQL_Agent_SprocJob" to pass parameters in.
Here is my parent runbook:
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!"
}
When I run this the runbook the runbook fails with the message:
Advanced parameter validation is not supported on nested workflows
In this link here they are showing this is the way to run nested runbooks:
Any idea where is the issue?