不支持的关键字:天蓝色集成连接的“身份验证"错误 [英] Keyword not supported: 'authentication' error for azure integrated connection

查看:110
本文介绍了不支持的关键字:天蓝色集成连接的“身份验证"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不支持获取关键字:尝试通过.NET core 2.1项目中的"Active Directory Integrated"选项连接Azure数据库时出现身份验证"错误.

Getting Keyword not supported: 'authentication' error while trying to connect an azure DB through 'Active Directory Integrated' option in .NET core 2.1 project.

注意:我正在使用EF内核连接数据源.

Note: I am using EF core to connect the Data source.

推荐答案

更新-16/08/2019
现在已在 Microsoft.Data.SqlClient 1.0.19221.1-Preview

UPDATE - 16/08/2019
Active Directory Password Authentication has now been added for .NET Core in Microsoft.Data.SqlClient 1.0.19221.1-Preview

遗憾的是,.net Core尚未完全支持authentication关键字.这是问题,对此进行了讨论.

Unfortunately, the authentication keyword is not yet fully supported in .NET Core. Here is an issue which discusses this.

但是.NET Core 2.2已添加对此用例的一些支持,如本

But .NET Core 2.2 has added some support for this use case as mentioned in this comment. The basic idea is to get the access token by any means (ADAL, REST, etc.) and set SqlConnection.AccessToken to it.

关于将此功能与EF Core一起使用,在 github问题中对此进行了很好的讨论,尤其是mgolois的评论提供了一种简单的实现 cbriaball在线程中提及的解决方案.

As for using this with EF Core, there's a good discussion about this in this github issue and in particular the comment by mgolois provides a simple implementation to the solution that cbriaball mentions in the thread.

此处与供参考的相同

请注意,此示例使用的是 Microsoft.Azure.Services.AppAuthentication

// DB Context Class
public class SampleDbContext : DbContext
{
  public SampleDbContext(DbContextOptions<TeamsDbContext> options) : base(options)
  {
    var conn = (System.Data.SqlClient.SqlConnection)this.Database.GetDbConnection();
    conn.AccessToken = (new AzureServiceTokenProvider()).GetAccessTokenAsync("https://database.windows.net/").Result;
  }
}

// Startup.cs
services.AddDbContext<SampleDbContext>(options =>
{
  options.UseSqlServer(<Connection String>);
});

连接字符串应该是这样的
Server=tcp:<server_name>.database.windows.net,1433;Database=<db_name>;

The connection string would be something like this
Server=tcp:<server_name>.database.windows.net,1433;Database=<db_name>;

这篇关于不支持的关键字:天蓝色集成连接的“身份验证"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆