Q: Your staging App Service slot works perfectly, but after swapping to production, the application connects to the staging database. What went wrong?
Root-cause post-mortem and configuration fix for connection string bleeding when performing blue/green deployment slot swaps in Azure App Service.
Want to master this scenario in a live sandbox? KodeKloud's PostgreSQL Database Administration & High Availability Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: This occurs because the database connection string was configured as a 'swappable' setting rather than a 'Deployment slot setting' (sticky setting). During a slot swap, Azure swaps app settings unless they are explicitly marked as sticky.
Understand Azure App Service Swap Mechanics
When you execute a slot swap, Azure swaps the virtual IP addresses and routing rules. By default, application configuration settings also swap between slots unless 'Deployment slot setting' is checked.
Configure Sticky Settings for Environment-Specific Configs
Flag environment-specific settings (Database connection strings, Redis caches, Key Vault URIs) as 'slot-specific' (sticky) in Azure CLI or Terraform so they remain bound to their respective slots.
# Set sticky connection string via Azure CLI
az webapp config connection-string set \
--name app-production-eus \
--resource-group rg-production \
--connection-string-type SQLAzure \
--settings DatabaseConnectionString="Server=tcp:sql-prod..." \
--slot-settings DatabaseConnectionString
Terraform Sticky Configuration Enforcement
In Terraform, declare the connection strings inside sticky_settings blocks in azurerm_app_service to ensure IaC prevents drift.
resource "azurerm_app_service" "app" {
# ...
sticky_settings {
connection_string_names = ["DatabaseConnectionString"]
app_setting_names = ["ENVIRONMENT", "APPINSIGHTS_INSTRUMENTATIONKEY"]
}
}
- Mark database connection strings as sticky (slot-specific) settings so they stay bound to the slot.
- Use az webapp config connection-string set --slot-settings to lock production values.
- In Terraform, specify sticky_settings { connection_string_names = [...] } to prevent drift.
- Perform warm-up pings and staging validation before initiating production swaps.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Applying exclusive-lock DDL table migrations on live production databases during peak traffic windows when configuring Azure Service Staging DDL migrations that acquire an exclusive table lock block all concurrent queries, queuing connections until the database connection pool exhausts.
- Allowing high-frequency queries to trigger full table scans without appropriate composite indexing when configuring Azure Service Staging Sequential table scans saturate database CPU and disk I/O, evicting frequently queried data from the buffer cache and causing cascading timeouts.
- Disabling referential integrity constraints during bulk ETL imports without post-import consistency validation when configuring Azure Service Staging Skipping relational consistency checks risks introducing orphaned records and referential integrity violations into production tables.
- Relying on database snapshot backups that have never been verified through automated restoration drills when configuring Azure Service Staging Backups that have never been tested with automated restore verification frequently fail during real disaster recovery scenarios.