首页 > 解决方案 > Azure DevOps 连接到 Azure SQL 连接字符串错误

问题描述

我正在尝试使用 Azure DevOps 创建解决方案。我需要使用发布/管道中的 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,因为它不受支持。你知道我应该如何面对这个问题吗?

标签: azure-devopsazure-sql-databaseazure-powershell

解决方案


用同样的脚本测试,看来这个问题的原因是agent type

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

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

在此处输入图像描述

所以你可以检查代理类型(windows 或 linux)。

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


推荐阅读