We have an Azure Functions (.NET 8 Isolated) application connecting to Azure SQL Database using Microsoft Entra authentication via Managed Identity.
For the last couple of months we have been seeing intermittent authentication failures, but have been unable to identify a root cause. This has been happening only on our DEV environment, but recently started happening on our TEST environment.
Environment:
Azure Functions (.NET 8 Isolated)
Azure SQL Database
Microsoft Entra authentication using Managed Identity
Deployment slots enabled
EF Core using
AddDbContextFactoryservices.AddDbContextFactory(options => { options.UseSqlServer(connectionString, sql => sql.EnableRetryOnFailure( maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(10), errorNumbersToAdd: null)); });
The SQL users are created from external providers and granted the required database permissions.
The recurring error is:
Microsoft.Data.SqlClient.SqlException (0x80131904):
Login failed for user ''.
The behaviour is intermittent and difficult to reproduce.
The application can run successfully for days or weeks.
The error then starts occurring without any deployment or configuration change.
One affected Function App had not been deployed for approximately four months when the issue first appeared.
The issue affects some Function Apps while others continue to operate normally.
Moving Function Apps to a different App Service Plan did not eliminate the problem.
Swapping deployment slots appears to temporarily resolve the issue, sometimes.
Restarting the Function App also appears to help in some cases.
We have:
Verified database permissions.
Verified the managed identity exists in the database.
Created a duplicate Azure SQL server and database and successfully connected using Managed Identity.
Compared production and deployment slot configuration and found no meaningful differences.
Compared app settings, connection strings, identities, runtime versions, and networking settings between slots.
We also created SQL username/password logins and switched the application to use SQL authentication instead of Managed Identity.
When using SQL username/password authentication, the application remains stable and the issue does not recur.
This appears to suggest the problem is related specifically to Entra/Managed Identity authentication rather than general SQL connectivity.
I have had support queries with both the Azure Database and Function App teams without resolution.
Has anyone encountered intermittent Login failed for user '' errors with Azure Functions and Managed Identity where the managed identity user already exists and permissions are correctly configured?
If so, what was the root cause?