我试图从 azure automation run book power shell 自动从 azure SQL 数据库中检索数据。我发现 Azure 自动化帐户的模块中缺少 SQL Server 模块。我已经导入了那个模块。但是该命令仍然不起作用。
问问题
604 次
2 回答
1
如果我从模块库中导入默认的 SqlServer 版本(21.0.17224),我也可以重现您提到的问题。
术语“Invoke-Sqlcmd”未被识别为 cmdlet 的名称
请尝试使用SqlServer 21.0.17199,它在我这边工作正常。
于 2018-03-26T06:46:02.850 回答
1
Invoke-Sqlcmd 在 azure 自动化 Runbook Powershell 中不起作用。
所以我曾经使用 powershell 工作流来执行该查询。它执行成功。以下命令是连接到数据库并执行查询的 powershell 工作流程运行手册。
workflow "runbookValue"
{
inlinescript
{
$MasterDatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
$MasterDatabaseConnection.ConnectionString = "ConnectionStringValue"
# Open connection to Master DB
$MasterDatabaseConnection.Open()
# Create command
$MasterDatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
$MasterDatabaseCommand.Connection = $MasterDatabaseConnection
$MasterDatabaseCommand.CommandText = "<execute the query>"
# Execute the query
$MasterDatabaseCommand.ExecuteNonQuery()
# Close connection to Master DB
$MasterDatabaseConnection.Close()
}
}
于 2018-03-29T09:52:04.247 回答