c# - 使用 Active Directory 连接到 Azure DB - 通用,并在 C# 中使用 MFA 支持身份验证

标签 c# azure azure-active-directory azure-sql-database multi-factor-authentication

我需要从 C# 控制台应用程序访问 SQL 表数据的某些部分。我需要帮助从 C# 建立服务器连接。

数据库详细信息:

 Server type : Database Engine
 Authentication : Active Directory-Universal with MFA support.

另外,请告诉我我应该如何提供我的连接属性?

最佳答案

如果您不想摆弄 token 或将 C# 应用程序注册为 Azure 应用程序,则可以将 ODBC 或 OLE DB 与 MSOLEDBSQL driver 一起使用。 ,它能够立即使用 MFA/ActiveDirectoryInteractive 身份验证:

ODBC:

using System.Data.Odbc;
...
OdbcConnection con = new OdbcConnection("Driver={ODBC Driver 17 for SQL Server};SERVER=sqlserver.database.windows.net;DATABASE=database;Authentication=ActiveDirectoryInteractive;<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="df8a969be2aaacbaad9fbbb0b2beb6b1f1bcb0b2" rel="noreferrer noopener nofollow">[email protected]</a>");

OLE 数据库:

using System.Data.OleDb;
...
OleDbConnection con = new OleDbConnection("Provider=MSOLEDBSQL;Data Source=sqlserver.database.windows.net;User <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9e0ed94dcdaccdbe9cdc6c4c8c0c787cac6c4" rel="noreferrer noopener nofollow">[email protected]</a>;Initial Catalog=database;Authentication=ActiveDirectoryInteractive");

关于c# - 使用 Active Directory 连接到 Azure DB - 通用,并在 C# 中使用 MFA 支持身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56215700/

相关文章:

c# - "Could Not load file or assembly"天蓝色网络应用程序

c# - 如何从 IronRuby 调用 C# IEnumerable

c# - 加入声明和分配或不加入...这是个问题

c# - 为什么从类派生会导致有关父构造函数的错误?

azure - 使用 ARM 将 PFX 证书添加到 Azure WebApp(不适用于 ssl)

azure - 如何查看负载均衡器中实例的运行状况?

Azure队列: find whether item is in queue

azure-active-directory - 代币发行(AADSTS50013 : Assertion contains an invalid signature)

azure - 在 Azure 中,如何使两个事件目录共享同一个应用程序?

azure - AADSTS70005 : response_type 'id_token' is not enabled for the application