gpt4 book ai didi

azure - System.Private.CoreLib : Exception while executing function: System. Data.SqlClient:不支持关键字: 'authentication'

转载 作者:行者123 更新时间:2023-12-03 02:53:32 25 4
gpt4 key购买 nike

我正在编写一个函数来记录使用 Entity Framework 核心上传到 blob 存储帐户的每个文件的信息。当我尝试连接到 azure sql 数据库时,出现以下错误:

System.Private.CoreLib: Exception while executing function: BlobStorageLogging. System.Data.SqlClient: Keyword not supported: 'authentication'

我从 Azure 门户复制了连接字符串:

"DefaultConnection": { "ConnectionString": "Server=tcp:dbserver.database.windows.net,1433;Initial Catalog=loggingdb;Persist Security Info=False;User ID={*****}; MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication=\"Active Directory Integrated\";",

"ProviderName": "System.Data.SqlClient" }

导致错误的代码是:

  var optionsBuilder = new DbContextOptionsBuilder<LoggingDBContext>();
var options = optionsBuilder.UseSqlServer(connectionString, providerOptions => providerOptions.CommandTimeout(60)).Options;
using (var context = new LoggingDBContext(options))
{
context.Database.ExecuteSqlCommand("TRUNCATE TABLE [dbo].[BlobInfo]");

我尝试删除身份验证,但这导致了未经授权的错误。任何帮助将不胜感激。

最佳答案

目前预计会出现异常,请检查thread .

SqlClient for .NET Core still does not support using the 'authentication' keyword in the connection string. That will happen when this issue is actually fixed.

In order to use AAD in the new version of SqlClient in .NET Core 2.2, customers need to obtain the access token themselves using ADAL.NET and then set the AccessToken property on the SqlConnection

这意味着在.NET Core中,Active Directory集成身份验证不可用,要使用Active Directory密码身份验证,我们必须获取访问 token ,这在EF中似乎不太理想配置。

解决方法是使用连接字符串进行 SQL 身份验证

关于azure - System.Private.CoreLib : Exception while executing function: System. Data.SqlClient:不支持关键字: 'authentication',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54577814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com