我需要从 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/