I'm brand new to automation, and am trying to get a runbook to connect to a sql database and run a stored procedure. The problem is, the code I'm using (adapted from https://azure.microsoft.com/en-us/blog/azure-automation-your-sql-agent-in-the-cloud/) is not asking for the server and credentials parameters when I try to test it. The test window says, "No input parameters."
Here is my (genericized) code:
workflow DB_DailyTasks
{
param
(
# Fully-qualified name of the Azure DB server
[parameter(Mandatory=$true)]
[string] $SqlServerName="mydb.database.windows.net",
# Credentials for $SqlServerName stored as an Azure Automation credential asset
# When using in the Azure Automation UI, please enter the name of the credential asset for the "Credential" parameter
[parameter(Mandatory=$true)]
[PSCredential] $Credential
)
inlinescript
{
# Setup credentials
$ServerName = $Using:SqlServerName
$UserId = $Using:Credential.UserName
$Password = ($Using:Credential).GetNetworkCredential().Password
# Execute the udp_Test procedure
# Create connection for each individual database
$DatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
$DatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
$DbName = "myDB"
# Setup connection string for $DbName
$DatabaseConnection.ConnectionString = "Server=$ServerName; Database=$DbName; User ID=$UserId; Password=$Password;"
$DatabaseConnection.Open();
# Create command for a specific database $DBName
$DatabaseCommand.Connection = $DatabaseConnection
Write-Output "Running udp_Test procedure"
$DatabaseCommand.CommandText = "EXECUTE [dbo].[udp_Test]"
$NonQueryResult = $DatabaseCommand.ExecuteNonQuery()
# Close connection to $DbName
$DatabaseConnection.Close()
}
}
I have some stored credentials in the automation account, but I can't get the test to actually ASK for them! When I test, it says, "No input parameters." Is there something I'm doing wrong?