# System.InvalidOperationException: The ConnectionString 'DefaultConnection' has an invalid format. Expected format: 'Server=tcp:...;Database=...;User ID=...;Password=...;'

- **ID:** `cloud/azure-app-service-connection-string-format`
- **Domain:** cloud
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

Azure App Service connection strings stored in app settings often have incorrect syntax (e.g., missing semicolons, wrong key names, or using non-SQL Server format for SQL Database).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Azure App Service Windows | active | — | — |
| Azure App Service Linux | active | — | — |
| .NET 8 | active | — | — |

## Workarounds

1. **Use the correct format for Azure SQL Database in app settings: Server=tcp:<server>.database.windows.net,1433;Database=<db>;User ID=<user>@<server>;Password=<password>;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;** (95% success)
   ```
   Use the correct format for Azure SQL Database in app settings: Server=tcp:<server>.database.windows.net,1433;Database=<db>;User ID=<user>@<server>;Password=<password>;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
   ```
2. **Retrieve the connection string from the Azure Portal: go to your SQL Database -> Connection strings -> ADO.NET, then copy the exact string and paste it into App Service's 'Connection strings' section, selecting 'SQLAzure' as the type.** (90% success)
   ```
   Retrieve the connection string from the Azure Portal: go to your SQL Database -> Connection strings -> ADO.NET, then copy the exact string and paste it into App Service's 'Connection strings' section, selecting 'SQLAzure' as the type.
   ```
3. **Use a Key Vault reference with proper syntax: @Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/myconnectionstring/). Ensure the App Service has 'Key Vault Secrets User' role on the vault.** (85% success)
   ```
   Use a Key Vault reference with proper syntax: @Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/myconnectionstring/). Ensure the App Service has 'Key Vault Secrets User' role on the vault.
   ```

## Dead Ends

- **** — Adding extra quotes around the connection string in app settings causes parsing errors. (95% fail)
- **** — Using Key Vault references without proper syntax like @Microsoft.KeyVault(SecretUri=...) results in the raw reference string being used as the connection string. (80% fail)
- **** — Copying a connection string from SQL Server Management Studio that includes 'Trusted_Connection=True' fails because Azure SQL requires SQL authentication. (85% fail)
