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

.net-core azure azure-functions azure-sql-database entity-framework-core

Question

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
1
2/7/2019 4:24:28 PM

Accepted Answer

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.

1
2/21/2019 8:42:36 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow