1
votes

I am writing a function to log information from every file uploaded to a blob storage account using entity framework core. When I try to connect to the azure sql db, I get the following error:

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

I copied my connection string from the azure portal:

"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" }

The code that is causing the error is:

  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]");

I have tried removing the authentication but that resulted in an unauthorized error. Any help would be appreciated.

1
Hi Bishop, if the solution did some help, do you mind accepting it as the answer for others to refer?Jerry Liu

1 Answers

1
votes

The exception is expected for now, check the 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

It means in .NET Core, Active Directory Integrated authentication is unavailable, to use Active Directory password authentication, we have to obtain access token which seems not ideal in EF configuration.

The workaround is to use Connection string for SQL authentication.