使用Active Directory密码从C#连接到Sql Azure Db时遇到问题

问题描述 投票:1回答:1

我正在建立一个Azure数据库,CRM 360数据导出服务(DES)需要连接到该数据库。我可以使用SSMS手动执行此操作,并使用我的Azure帐户登录。

enter image description here

然后将DES服务帐户设置为外部提供程序。

从外部提供商创建用户DynamicsDataExportService

很好,但是我希望自动化该过程,因此我需要使用C#登录到该服务并以这种方式连接并运行代码。

我正在使用以下代码在System.Data.SqlClient 4.7上运行核心2.2:

        var cs = "data source=tcp:dvzxfsdg-sql.database.windows.net,1433;initial catalog=dfsdfs-sqldb; Authentication=Active Directory Integrated";
        using (var connection = new SqlConnection(cs))
        {
            connection.Open();

令人讨厌的是,它给出错误“ System.ArgumentException:'不支持的关键字:'authentication'。'”。我敢肯定我犯的错误是很基本的,但是我似乎无法深究它。因此,非常感谢您收到任何指针。

c# sql azure crm des
1个回答
0
投票

您可能想尝试使用SQLConnectionStringBuilder正确格式化连接字符串。这有助于避免使用纯文本连接字符串时可能造成的拼写错误和问题。

例如:

SqlConnection conn = new SqlConnection(
    new SqlConnectionStringBuilder ()
    {
        DataSource = "dvzxfsdg-sql.database.windows.net",
        InitialCatalog = "dfsdfs-sqldb",
        UserID = "UserName",
        Password = "UserPassword"
    }.ConnectionString
);

有关构建连接字符串的更多信息,请参阅this answer

© www.soinside.com 2019 - 2024. All rights reserved.