Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid value for key 'authentication'

I have a .NET Core 3.0 app where am trying to connect to a Azure SQL database using EF Core and Active directory integrated authentication.
I have verified that I have access to this database from my machine as I can connect to it just fine using SQL server management studio and 'Azure Active Directory-Integrated' authentication.

However, when I try to read data in my app (using EF Core), I always get a System.Argument exception with the following statement:

Invalid value for key 'authentication'

Exception details point to the Db connection string.

So, here is my connection string from my dev appsettings.json file:

"ConnectionStrings": { "MCDB": "Server=tcp:dev-media-center-sql.database.windows.net,1433;Initial Catalog=MediaCenter;Persist Security Info=False;User ID={my User ID};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication=Active Directory Integrated;" },

I have tried hard coding the connection string directly in my code, thinking that there might be a problem with my JSON but I still get the same exception.

Is "Active Directory Integrated" not a valid value for the 'Authentication' keyword? If not, what is it then? I have already tried "ActiveDirectoryIntegrated" (with no spaces) and /"Active Directory Integrated"/ (escaping double quotes) but to no avail.

Thanks

Fike

like image 619
Fike Rehman Avatar asked Jan 08 '20 22:01

Fike Rehman


People also ask

How do I use managed identity to SQL database?

In order to allow managed identities to connect to Azure SQL Database, you need to enable Azure Active Directory (AD) authentication and create the managed users in the database. To enable Azure AD authentication for your Azure SQL Server, make sure there is an Azure AD admin configured for the database server.


1 Answers

Here's what did it for me:

If you're using EF Core with package Microsoft.EntityFrameworkCore.SqlServer...

Then be aware:

The Microsoft.Data.SqlClient package ships more frequently than the EF Core provider. If you would like to take advantage of new features and bug fixes, you can add a direct package reference to the latest version of Microsoft.Data.SqlClient.

source: https://docs.microsoft.com/en-us/ef/core/providers/sql-server/?tabs=dotnet-core-cli

That being said 👆, the fix was EASY. Just add the package to your project 👇

enter image description here

like image 80
Francisco Vilches Avatar answered Sep 21 '22 08:09

Francisco Vilches