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

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

问题描述

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

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

不幸的是,authentication 关键字在 .NET Core 中尚不完全支持.这是一个 issue 讨论了这个问题.

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

但是 .NET Core 2.2 已添加对此用例的一些支持,如本 评论.基本思想是通过 任何方式(ADAL、REST等)并将SqlConnection.AccessToken设置为它.

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 问题中有很好的讨论a> 特别是 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 图书馆

Note that this sample is using the Microsoft.Azure.Services.AppAuthentication library

// 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>;

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

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