How To Disable Azure SQL Auto-Pause on Free Tier

How To Add DC4 Workload Profile in Azure Container Apps

Written by

in

If you’re using the free tier of Azure SQL Database, you should know that completely turning off Auto-pause isn’t possible. This feature is built into the free plan because it helps manage costs by automatically pausing the database during periods of inactivity. Unfortunately, there’s no setting that allows you to keep the database always running while still using the free offer.

What happens often is related to how your application starts up. When the database is paused, the very first time your application tries to connect or run a query, it has to wait for the database to wake up. During this time, the connection attempt might time out, causing your app to fail to start properly. This failure can lead to errors like a 500.30 status, meaning the ASP.NET Core application couldn’t launch correctly. Even after the database wakes up, the application won’t restart automatically. That’s why restarting the app sometimes fixes the issue temporarily.

The best way to handle this situation without incurring extra costs is to make your app resilient to short database downtimes. If you’re using Entity Framework Core, you can enable retry logic for database connections by adding the EnableRetryOnFailure option. Here’s how you can set it up:

csharp
options.UseSqlServer(connectionString, sqlOptions =>
sqlOptions.EnableRetryOnFailure(
maxRetryCount: 5,
maxRetryDelay: TimeSpan.FromSeconds(30),
errorNumbersToAdd: null));

This tells your application to automatically retry connecting to the database if an initial attempt fails, rather than giving up immediately. But if your application has critical startup steps that depend on the database, you should also modify your startup code. The goal is to let the application start and be ready to handle database connections once the database is awake, rather than stopping altogether because the database is temporarily unavailable.

In conclusion, if you want to stay within the free plan, there isn’t a way to keep the database running constantly without Auto-pause. The better approach is to build your application so it can tolerate brief delays during startup. This not only solves the current issue but also makes your app more reliable overall, because databases can sometimes be temporarily inaccessible for reasons other than Auto-pause.

If this advice helps, please consider marking it as the accepted answer. It helps others who face the same challenge find a solution more quickly. Thank you!