Blazor Web App SqlException: Login failed for user When deployed to Azure

Braden Bowie 40 Reputation points
2025-05-06T00:21:36.7033333+00:00

Hi,

I have a .Net 8 Blazor Web App, for some reason whenever I deploy the web app to an Azure Web app I get the following error SqlException: Login failed for user 'dummyUser'.

The issue is intermittent, it usually occurs for the first 5 or so min after publishing, then goes away for a bit. But then the error will pop up randomly at different times.

I tried the same app settings locally and there is never an issue. Further I found that TrustServerCertificate=True will prevent the error from occurring but I want this to be false for greater security.

Both the database and web app is hosted in azure, does anyone know what could be causing this?

It seems to occur most often when multiple db requests are sent at once, but sometimes even if only one.

Thanks

ASP.NET Core Training
ASP.NET Core Training
ASP.NET Core: A set of technologies in the .NET Framework for building web applications and XML web services.Training: Instruction to develop new skills.
66 questions
0 comments No comments
{count} votes

Accepted answer
  1. Pradeep M 8,585 Reputation points Microsoft External Staff Moderator
    2025-05-06T03:33:15.3566667+00:00

    Hi Braden Bowie,  

    Thank you for reaching out to Microsoft Q & A forum. 

    The intermittent SqlException: Login failed for user 'dummyUser' issue after deploying your .NET 8 Blazor Web App to Azure may be occurring due to a few common reasons: 

    1.App Initialization Timing: Right after deployment, the application settings may not be fully loaded, which can lead to login failures. Implementing retry logic (such as using Polly) can help handle these temporary issues. 

    2.Connection String Settings: Please ensure the connection string configured in your Azure App Service is correct and consistent with what works locally. If possible, using Managed Identity is a more secure and reliable option than hardcoding credentials. 

    3.TrustServerCertificate=False: When this is set, the application requires a valid, trusted SSL certificate. Ensure that your Azure environment is able to validate the SQL server's certificate. As a temporary workaround, TrustServerCertificate=True can help, but it is less secure. 

    4.High Load or Concurrent Requests: If the error appears during multiple simultaneous database requests, it may be related to connection pooling or DbContext usage. Please ensure that DbContext is registered with a Scoped lifetime in your Blazor Server app. 

    Lastly, enabling Application Insights or Azure diagnostic logging can provide more clarity on when and why the failures occur. 

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community. 


0 additional answers

Sort by: Most helpful

Your answer

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