Search code examples
c#.netazure-sql-databaseazure-keyvault

Azure SQL database not available on first connection attempt


I have an Azure KeyVault secret which contains my database connection string to my Azure SQL database.

When my C# Windows Forms application loads it gets the KeyVault secret using my Default Azure Credentials and stores the connection string. My code then queries the Azure SQL database using that connection string.

My issue is that when I first run the application each day, I get an ‘System.Data.SqlClient.SqlException‘ error informing me the database is not currently available. Please retry the connection later. If I close the application and rerun it, it works as expected each time thereafter. The next day I have the same issue again.


Solution

  • Are you using a Serverless compute tier for Azure SQL Database?

    According to the documentation:

    If a serverless database is paused, the first sign-in activity resumes the database and returns an error stating that the database is unavailable with error code 40613.

    Workaround: