I have an ASP.NET web application running on prem windows server. We need to connect to an Azure SQL MI from the C# code. I tried as below example code:
string ConnectionString1 = @"Server=demo.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; Database=testdb";
using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
conn.Open(); //Erroring out
}
Error Message: Unhandled Exception: Microsoft.Data.Sqlclient.Sqlexception: ManagedIdentityCredential authentication failed: Managed identity response was not in the expected format.
What am I missing?
Note: I am able to connect to the same azure SQL managed instance via SQL server Management studio using active directory authentication. Seeing the issue only when we try to establish connectivity from the c# code