-1

This is the closest post I could find that relates to my issue. Hope you don't mind my piggy-backing.

My connection string works in VS Code but breaks in Azure with the following error:

ManagedIdentityCredential authentication failed: Service request failed.

My connectionstring looks like:

Server=tcp:asi-sql-dev.database.windows.net,1433;Initial Catalog=anabelle;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication='Active Directory Default'

and when configuring EF Core I do the following:

var connectionString = string.Empty;
if (builder.Environment.IsDevelopment())
{
    connectionString = builder.Configuration.GetConnectionString("AzureSQL");
}
else
{
    connectionString = Environment.GetEnvironmentVariable("AzureSQL");
}

builder.Services.AddDbContext<DataContext>(options =>
{
    options.UseSqlServer(connectionString);
});

What am I missing?

I have tried multiple workarounds and looked at several posts. The closest I can get to is Microsoft.Data.SqlClient.SqlException (0x80131904): ManagedIdentityCredential authentication failed: Service request failed

When changing the connection string to normal UN / PW it works in Azure.

1 Answers1

0

So - after reviewing the order in which "Active Directory Default" tries to authenticate, I reviewed my app settings - I had the AZURE_CLIENT_ID and TENANT_ID set - with no secret and this confused it.

Removing those entries, dropping the SQL User and Recreating it solved the problem.

https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/azure-active-directory-authentication?view=sql-server-ver16#using-active-directory-default-authentication