Active Directory 服务主体为键 'authentication' 提供了无效值

Active Directory Service Principal is giving Invalid value for key 'authentication'

我正在尝试执行一个 SSIS 包,其中源是 SQL 服务器,目标是 Azure SQL,身份验证为“Active Directory 服务主体”。 ODBC 驱动程序是 17.8,OLEDB 驱动程序是 18.5。

执行 SSIS 包时,脚本任务失败并出现此错误

Invalid value for key 'authentication'

使用以下连接字符串:

Server=tcp:servername.database.windows.net,1433;
    Initial Catalog=DBName;Persist Security Info=False;
    User ID=clientid;Password=secrets;
    Authentication="Active Directory Service Principal";
    MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;

脚本任务正在​​使用 System.Data.SQLClient 库并以 .NET Framework v4.7 为目标

SSIS package is using System.Data.SQLClient version 4.0.0, Is there any way we can use service principal authentication without using Microsoft.Data.SqlClient??

System.Data.SQlClient 仅支持 SQL 身份验证AAD 用户帐户身份验证 .

因此,如果您想使用 Service Principal 或其他身份验证方法,那么您应该使用 Microsoft.Data.SQLClient,因为它从版本 2.0.0+ 开始支持.

从 dotnet CLI 安装 Microsoft.Data.SQLClient 包的命令:

dotnet add package Microsoft.Data.SqlClient --version 3.0.1

那么你可以使用下面的:

string ConnectionString = @"Server=servername.database.windows.net; Authentication=Active Directory Service Principal; Database=testdb; User Id=AppId; Password=secret";

using (SqlConnection conn = new SqlConnection(ConnectionString)) {
    conn.Open();
}

参考:

Using Azure Active Directory authentication with SqlClient - ADO.NET Provider for SQL Server | Microsoft Docs