connect-to-azure-sql
Installation
SKILL.md
Connect to Azure SQL Database
Opening one connection is easy. Two things go wrong: the first connection is expected to fail and the code has no retry, and a certificate error gets fixed by turning verification off.
Flags and defaults below were verified 2026-09-03 against sqlcmd 1.10.0 and User Secrets Manager
8.0.27 on this machine; cloud behaviour is from Microsoft Learn.
Connect once from the command line before writing any code
Settle the server, database, credential and certificate before an application is in the picture, so every later failure is a failure of the code. Cloud, SQL authentication, password out of the command line:
sqlcmd -S <server>.database.windows.net,1433 -d <database> -U <user> -P "$SQL_PASSWORD" \
-N mandatory -l 30 -Q "SELECT DB_NAME() AS db, encrypt_option FROM sys.dm_exec_connections WHERE session_id = @@SPID"