我一直在尝试根据 this 使 使用 SQL 数据库的 Azure Active Directory 身份验证适用于我们的 Web API和 this微软资源。但是我无法从我们的应用程序连接到 Azure SQL。
我在 Azure 上设置了Active Directory 管理员。
然后我在 Azure 上的 Active Directory 中创建了一个组“dbusers”。 Active Directory 管理员也被分配到该组。
我使用以下命令在数据库上设置它。
CREATE USER [dbusers] FROM EXTERNAL PROVIDER;
到这里为止的一切都已成功完成。
我将应用程序中的 web.config 更新为以下内容:
Data Source=[my azure db]; Authentication=Active Directory Integrated; Initial Catalog=[my db name];
当我尝试从 Web API 连接到数据库时,出现以下异常:
Exception message: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection., Exception stacktrace: at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
我发现了一个workaround using following line :
Database.SetInitializer<MyDbContext>(null);
这让我想到了另一个众所周知的好例子:
Exception message: The underlying provider failed on Open., Exception stacktrace: at System.Data.Entity.Core.EntityClient.EntityConnection.d__8.MoveNext()
我开始对如何配置它感到疯狂。
我不确定我在 Azure 上的配置是否有错误,或者我的连接字符串是否有问题,或者是否存在与此问题完全不同的问题。
编辑:
要求之一是:
To use integrated Windows authentication, your domain’s Active Directory must be federated with Azure Active Directory. Your client application (or a service) connecting to the database must be running on a domain-joined machine under a user’s domain credentials
我们正在使用 Azure Web App 和 Azure SQL。我如何找到此信息,或者在不运行专用虚拟机的情况下这是否可能?
最佳答案
由于您正在 Active Directory Integrated 下运行所有内容, 您是否尝试使用 SSMS 并使用 Windows 凭据连接到数据库?作为特定 Windows 用户连接是否成功 另一种方法是使用 AAD 用户/密码 也基于你的字符串 数据源=[我的 azure 数据库];身份验证=Active Directory 集成;初始目录=[我的数据库名称]; 数据源表示格式为 myazureserver.database.windows.net 的服务器名称 和数据库 数据库名 此外,您已在 mydbname 中创建了用户“dbusers” - 正确吗?
关于sql-server - 使用 SQL 数据库进行 Azure Active Directory 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49857587/