### Production Azure SQL connection with managed identity and retries Source: https://learn.microsoft.com/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server Use this snippet as a starting point for a production-oriented Azure SQL connection. It loads server and database names from application configuration (e.g., Azure App Service app settings, environment variables, or config file) and sets connection properties programmatically. The configuration combines TLS, managed identity, connection retries, fast failover, a longer login timeout, and configurable retry logic (CRL) for Azure SQL throttling and mid-query failover. Note: Java snippets omit imports and class wrappers for brevity. ```java // Load endpoint details from application configuration. In Azure App Service, // these can come from app settings or Key Vault-backed settings. String serverName = System.getenv("SQL_SERVER_NAME"); String databaseName = System.getenv("SQL_DATABASE_NAME"); String port = System.getenv().getOrDefault("SQL_PORT", "1433"); if (serverName == null || databaseName == null) { throw new IllegalStateException( "Set SQL_SERVER_NAME and SQL_DATABASE_NAME in your application configuration."); } String url = "jdbc:sqlserver://" + serverName + ":" + port; Properties props = new Properties(); props.setProperty("databaseName", databaseName); props.setProperty("encrypt", "true"); props.setProperty("trustServerCertificate", "false"); props.setProperty("authentication", "ActiveDirectoryManagedIdentity"); props.setProperty("loginTimeout", "120"); // bounds the whole retry sequence, not just one attempt props.setProperty("connectRetryCount", "5"); // retry transient connection failures up to 5 times (default 1) props.setProperty("connectRetryInterval", "15"); // 15 seconds between connection retries (default 10) props.setProperty("multiSubnetFailover", "true"); // parallel dials to all resolved IPs; safe on single-IP targets // props.setProperty("applicationIntent", "ReadOnly"); // uncomment to route to a readable secondary // Retry deadlocks and lock timeouts, plus Azure SQL throttling and mid-query failover. props.setProperty("retryExec", "1205,1222:3,5+5;40501,40613,40197,10928,10929,49918:4,5*2"); try (Connection conn = DriverManager.getConnection(url, props); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT 1")) { while (rs.next()) { System.out.println(rs.getInt(1)); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.