This is most likely a connection-idle issue rather than a Blazor page issue.
Azure SQL Database can terminate idle connections after about 30 minutes when the connection is idle at the TDS/query layer, even if TCP keepalive is present. That matches the pattern described: the app works, sits idle for 20–30 minutes, then fails on the next database access.
The connection string is not the main problem based on the idle timing alone. The important parts already align with recommended settings:
- Use the fully qualified Azure SQL server name and port
1433
- Keep
Encrypt=True
- Keep
TrustServerCertificate=False
- Use a connection timeout of at least 30 seconds
Recommended checks and fixes:
- Verify the server name format in the connection string.
- For Azure SQL Database, use the fully qualified server name in this form:
Server=tcp:<database-server-name>.database.windows.net,1433;
- If the current
Server=tcp:<DataBaseName>,<PortNumber>; value is not the Azure SQL fully qualified name, correct it.
- Confirm the database name placement.
-
Initial Catalog should be the database name.
- The server name belongs in the
Server= portion.
- Add retry logic in the app.
- Retry logic is strongly recommended for Azure SQL client applications so the app can reconnect after transient failures.
- The recommended first retry delay is 5 seconds, then increase delays exponentially up to 60 seconds.
- Check for stale DNS or hosts-file overrides.
- If failures happen only on certain networks, remove any hosts-file, static CNAME, or other DNS override for the Azure SQL FQDN, then flush DNS and retest.
- For Azure Static Web Apps, verify database access prerequisites.
- The database firewall must allow network access from Azure resources for Static Web Apps workers.
- Allowing specific Static Web Apps IP addresses is not supported.
- If Managed Identity authentication is used, the Static Web App managed identity must be granted access to the database.
- If using the JDBC driver anywhere in the stack, review idle connection handling.
- Azure SQL documentation notes that idle connections can be dropped by network devices or by the Azure SQL Gateway after 30 minutes of no active query.
- Using the Redirect connection policy is one documented way to avoid gateway termination of idle connections.
A corrected Azure SQL connection string shape would be:
Server=tcp:<database-server-name>.database.windows.net,1433;Initial Catalog=<database-name>;Encrypt=True;TrustServerCertificate=False;Connection Timeout=60;
A better long-term option is passwordless authentication instead of storing SQL username and password in the connection string. For Azure SQL, the recommended pattern is:
Server=tcp:<database-server-name>.database.windows.net,1433;Initial Catalog=<database-name>;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication="Active Directory Default";
If the current issue is specifically “fails after being idle,” the first practical fix is to implement retry logic and verify the server/database values in the connection string.
References: