簡體   English   中英

Active Directory密碼連接Azure自動化導致Azure SQL失敗

[英]Active Directory Password Connection Azure SQL Failure from Azure Automation

我需要使用設置為Azure SQL Server AZ AD Admin的Azure Active Directory Admin帳戶通過Azure Automation連接到Azure SQL Server。

我能夠連接到Azure SQL:

  1. 將SSMS與Azure AD管理員帳戶一起使用
  2. 在SQL ConnectionString中將PowerShell ISE與Azure AD管理員帳戶一起使用
  3. 在SQL ConnectionString中將Azure Automation與Azure SQL Admin帳戶(創建新的Azure SQL Server時創建的帳戶)一起使用

但是,當嘗試在SQL ConnectionString中使用Azure Automation中的Active Directory Admin帳戶連接到Azure Automation中的Azure SQL時,出現以下錯誤:

“新對象:使用” 1“參數調用” .ctor“的異常:”不支持的關鍵字:“身份驗證”。

這是我的連接嘗試:

$server = "tcp:myazuresql.database.windows.net,1433"
$database = "TestDB"
$adminName = "test@mytest.onmicrosoft.com"
$adminPassword = "test1234"

$connectionString = "Server=$server;Database=$database;User ID=$adminName;Password=$adminPassword;authentication=Active Directory Password;"
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection($connectionString)

關於為什么我可以通過PowerShell ISE和SSMS而不通過Azure Active Directory Admin通過Azure自動化進行連接的任何想法? 我還可以通過Azure自動化和Azure SQL管理員帳戶(您使用Azure SQL創建的默認管理員帳戶)進行連接。

我無法連接的唯一方法是在使用Azure自動化時使用綁定到Azure SQL的Azure Active Directory管理員。

Azure自動化帳戶尚不支持使用Azure AD連接到SQL。此功能需要.NET Framework 4.6,當前Azure Automation工作人員只有.NET Framework 4.5。

建議:

使用Azure自動化模塊

   ## Using Azure Automation ISE Add-on
    #Install-Module -Name AzureAutomationAuthoringToolkit
    Import-Module AzureAutomationAuthoringToolkit
    $SqlServer = "myazuresql.database.windows.net"
    $SqlServerPort = "1433"
    $Database = "TestDB"
    $Table = ""
    $SqlCredentialAsset = ""
    $SqlCredential = Get-AutomationPSCredential -Name $SqlCredentialAsset 
    if ($SqlCredential -eq $null) 
        { 
            throw "Could not retrieve '$SqlCredentialAsset' credential asset. Check that you created this first in the Automation service." 
        }   
    $SqlUsername = $SqlCredential.UserName 
    $SqlPass = $SqlCredential.GetNetworkCredential().Password 
    $Conn = New-Object System.Data.SqlClient.SqlConnection("Server=tcp:$SqlServer,$SqlServerPort;Database=$Database;User ID=$SqlUsername;Password=$SqlPass;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;")

    $Conn.Open() 
    $Cmd=new-object system.Data.SqlClient.SqlCommand("SELECT COUNT(*) from $Table", $Conn) 
    $Cmd.CommandTimeout=120 
    $Conn.Close()

RunBook內部的代碼

#Runbook
Param
(
[Parameter(Mandatory=$true)]
[String]
$AureConnectionName
)

$AzureConn = Get-AutomationConnection -Name $AzureConnectionName

If ($AuzreConn -eq $null)
{
    throw "Could not retrieve '$SqlCredentialAsset' credential asset."
}
$Certificate = Get-AutomationCertificate -Name $AzureConn.AutomationCertificateName

if ($Certificate -eq $null)
{
 throw "Could not retrieve '$AzureConn.AutomationCertificateName' certificate asset." 
}

$cred = Get-Credential -Credential Domain\User
Login-AzureRmAccount -Credential $cred
Get-AzureRmSubscription | Select-AzureRmSubscription

請參考這個類似的問題

如果要將SQL Server與Azure AD用戶連接,則應在VM上安裝ADAL SQL庫 現在,Azure自動化帳戶不會安裝庫。 如果要使用Azure AD用戶登錄SQL服務器,則可以選擇Hybrid worker

由於Azure中的Runbook在Azure雲中運行,因此它們無法訪問本地數據中心中的資源。 Azure自動化的Hybrid Runbook Worker功能允許您在數據中心中的計算機上運行Runbook來管理本地資源。 運行簿在Azure自動化中存儲和管理,然后交付到一台或多台本地計算機上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM