1
我需要执行批处理来执行我的数据库中的一些维护任务,但是我看到的Azure自动化上的所有示例都涉及到a single SQL command。如何在Azure Runbook中运行SQL批处理?
如何创建SP不是一个选项?我想我需要以某种方式将我的script.sql文件嵌入到runbook脚本或引用它(例如here,例如)?
我需要执行批处理来执行我的数据库中的一些维护任务,但是我看到的Azure自动化上的所有示例都涉及到a single SQL command。如何在Azure Runbook中运行SQL批处理?
如何创建SP不是一个选项?我想我需要以某种方式将我的script.sql文件嵌入到runbook脚本或引用它(例如here,例如)?
您可以将.sql文件存储在Azure Blob存储中,并在Runbook下载.sql文件,读取其内容并将其传递给SqlCommand对象。
喜欢的东西:
try {
# Connect to Azure using service principal auth
$ServicePrincipalConnection = Get-AutomationConnection -Name $AzureConnectionAssetName
Write-Output "Logging in to Azure..."
$Null = Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $ServicePrincipalConnection.TenantId `
-ApplicationId $ServicePrincipalConnection.ApplicationId `
-CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint
}
catch {
if(!$ServicePrincipalConnection) {
throw "Connection $AzureConnectionAssetName not found."
}
else {
throw $_.Exception
}
}
$Path = "C:\abc.sql"
Set-AzureRmCurrentStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName
Get-AzureStorageBlobContent -Container $Container -Blob $Blob -Destination $Path
$Content = Get-Content $Path
$Cmd = New-Object System.Data.SqlClient.SqlCommand($Content, $Conn)