作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要执行批处理以在数据库中执行一些维护任务,但我看到的 Azure 自动化上的所有示例都在处理 a single SQL command .
如果无法创建 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)
关于sql - 如何在 Azure Runbook 中运行 SQL 批处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37762720/
我是一名优秀的程序员,十分优秀!