Azure DevOps 连接到 Azure SQL 连接字符串错误

Azure DevOps Connect to Azure SQL Connection String error

我正在尝试使用 Azure DevOps 创建解决方案。我需要在 Release/Pipeline 中使用 Azure Powershell 任务创建到 Azure SQL 数据库的连接。 在我的机器上,我能够使用以下

实现此目的
function new-connection($ServerIsntance, $DatabaseName)
{
    $obj = New-Object System.Data.SQLClient.SQLCommand
    $obj.Connection = New-Object System.Data.SQLClient.SQLConnection
    $obj.Connection.ConnectionString = "Server=tcp:$($ServerInstance),1433;Initial Catalog=$($DatabaseName);Persist Security Info=False;User Id=<username>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication=Active Directory Password"
    $obj.Connection.Open()
    .....
}

然而,当我在 Azure DevOps 中使用此代码时,出现以下异常:##[error]Exception setting "ConnectionString": "Keyword not supported: 'authentication'."

我尝试使用的数据库是 AzureSQL,因此我无法使用 Integrated Security = true,因为它不受支持。您知道我应该如何面对这个问题吗?

https://docs.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver15

您的代码在 Active Directory Password 之间是否包含空格?如果是这样,请尝试删除它们,因为该文档不包含任何空格。

用同样的脚本测试,看来这个问题的原因是代理类型

当我使用 Windows 代理(例如 vs2017-win2016)时,脚本可以按预期运行。

但是当我使用 Linux agent(例如 ubuntu 16.04)进行测试时,我可能会遇到同样的问题。

因此您可以检查代理类型(windows 或 linux)。

您可以尝试使用 Windows Microsoft 托管的代理(例如 vs2017-win2016 、windows-2019)。