Authentication issue using Azure Managed Identity, SQL and C#

Dave Gray 586 Reputation points
2024-02-02T12:42:08.92+00:00

Hello First go at trying to use Azure Managed identity (MI) from a C# console app to connect to a Azure SQL Server but I'm getting an error regarding the Authentication key in the constructed connection string. The error is...

Invalid value for key 'authentication'.

My code will run on an app server for which I have enabled system assign MI in the Azure portal

Setup MI in Azure for the app server. In this case an IaaS running Windows.

mi

Created the user in my DB like this CREATE USER [MyServer] FROM EXTERNAL PROVIDER EXEC sp_addrolemember N'db_owner', N'MyServer' The C# code uses Dapper and System.Data.SqlClient mic sharp

I read of few articles about how to construct the connection string in C# and I think I have it right, howerver it does seem odd that I have the Authentication key specified twice. Any ideas anyone?

Thanks

Azure SQL Database
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Morillo 35,406 Reputation points MVP Volunteer Moderator
    2024-02-02T22:34:04.67+00:00

    Instead of using System.Data.SqlClient try downloading and using Microsoft.Data.SqlClient NuGet package. Maybe this article helps you solve the issue.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.