Details
# Azure SQL Database container
Run and build against Azure SQL Database, right on your local environment. Try it before you deploy, run your tests in CI, and ship with no code change. Free for development, with no Azure subscription and no credit card required.
[](https://aka.ms/sqldbcontainerpreview-signup)
[](https://aka.ms/azuresqldb-container)
[](https://aka.ms/azuresqldb-container-bug)
[](https://aka.ms/azuresqldb-container-feature-request)
[](../../discussions)
[](https://skills.sh/microsoft/azure-sql-database-container)
<a href="https://aka.ms/azuresqldb-container-demo">
<img src="docs/assets/img/container-cover.png" alt="Watch the Azure SQL Database container demo" width="760">
</a>
<a href="https://aka.ms/azuresqldb-container-demo">**▶ Watch the demo**</a>
The Azure SQL Database container is the Azure SQL Database engine, running locally. It runs on any modern container runtime (Docker, Podman, containerd, Rancher Desktop) on macOS, Linux, and Windows, and works with the drivers, ORMs, and editors developers already use. It supports the same AI-native capabilities as Azure SQL Database in the Microsoft Azure cloud: the native vector type, vector search with `VECTOR_DISTANCE`, in-database embeddings, and DiskANN vector indexes with `CREATE VECTOR INDEX`.
For the first time, developers can build, test, and ship applications against the Azure SQL Database engine without an Azure subscription and without a shared cloud instance. When you deploy to Azure SQL Database in the Microsoft Azure cloud, it is a connection-string change, not a code change.
> [!IMPORTANT]
> The container image is in a private registry. **[Sign up for the Private Preview](https://aka.ms/sqldbcontainerpreview-signup)** to get the registry username and password you need to pull it. Signing up is the only way to get access.
## Global Table of Contents
- [What is the Azure SQL Database container?](docs/what-is-the-container.md)
- [Goals of the Private Preview](docs/goals-of-the-private-preview.md)
- [Prerequisites](docs/prerequisites.md)
- [Getting Started](docs/getting-started.md)
- [Agent skills](docs/agent-skills.md)
- [Known limitations](docs/known-limitations.md)
- [Feedback and how to engage](docs/feedback-and-how-to-engage.md)
## Agent skills
Point your AI coding agent at the container and let it start the engine, provision the database, scaffold the schema, write the migrations, and build the data layer. The repo ships [17 agent skills](docs/agent-skills.md) that work in **Claude Code, Codex, Cursor, and VS Code with GitHub Copilot**:
```bash
npx skills add microsoft/azure-sql-database-container
```
Claude Code and Codex users can also install them as a native plugin (`/plugin marketplace add microsoft/azure-sql-database-container`). See the **[Agent skills page](https://microsoft.github.io/azure-sql-database-container/agent-skills.html)** for per-tool install and what each skill does, or [browse the skill source](skills/README.md).
Each skill carries its knowledge in layers (instructions, bundled `references/` with version-pinned config shapes, and an optional live layer via the public [Microsoft Learn MCP](https://learn.microsoft.com/en-us/training/support/mcp) for the current docs on demand). The MCP is optional; the skills work without it. See [Knowledge layers](skills/README.md#knowledge-layers) and [Using the Microsoft Learn MCP](skills/README.md#using-the-microsoft-learn-mcp-optional).
## Feedback
- File a bug: [GitHub Issues](https://aka.ms/azuresqldb-container-bug)
- Request a feature: [GitHub Issues](https://aka.ms/azuresqldb-container-feature-request)
- Report a problem with an [agent skill](skills/README.md): [Skill feedback](https://aka.ms/sql-agent-skills-feedback)
- Ask a question, share a build, suggest an idea: [GitHub Discussions](../../discussions)
- Connect with the team: [book a session](https://aka.ms/azuresqldb-container-meet) or email [azuresqldb-container@microsoft.com](mailto:azuresqldb-container@microsoft.com)
- Real-time conversation: the private Teams channel shared via the early-access feedback channel
See [Feedback and how to engage](docs/feedback-and-how-to-engage.md) for the full guide on which channel fits which question, and [SUPPORT.md](SUPPORT.md) for how to get help.
## Contributing
Pull requests are welcome. Read [CONTRIBUTING.md](CONTRIBUTING.md) first: it covers what we are looking for during the Private Preview, how to build the site locally, and the conventions the agent skills follow (which are easy to break in ways that only show up when an agent silently stops loading a skill).
## License
This Private Preview is governed by a separate Private Preview license shared with you during sign-up. The samples in this repository are released under the MIT license.
## Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.
## skills/azuresql-db-auth/SKILL.md
---
name: azuresql-db-auth
description: >-
Connects an app to the Azure SQL Database container securely, with a least-privilege
database user instead of the sa login, the right auth method per environment,
and safe handling of the connection secret. Use when a user asks "don't use sa
in my app", "create a least-privilege database user", "app login for SQL",
"which authentication should my app use", "secure the connection string",
"Encrypt / TrustServerCertificate", "store the connection string in Key Vault",
"dotnet user-secrets", "managed identity for Azure SQL", or "grant only the
roles my app needs". SQL auth locally, Microsoft Entra or managed identity in
the cloud, changing only the connection string. Reach for this before wiring an
app to connect as sa, or before committing a connection string to source.
---
# Connect securely to the Azure SQL Database container (least-privilege user, auth, secrets)
`sa` is a bootstrap/admin login for provisioning, not what your application should
connect as. This skill wires the app to a **least-privilege user**, picks the
**auth method per environment** (SQL locally, Microsoft Entra or managed identity
in the cloud, changing only the connection string), secures the connection, and
keeps the secret out of source control.
Re-measured on 2026-09-19 against the container image tag `18.0.226_4_147`, reporting
`EngineEdition` 5, Edition `SQL Azure`, build `12.0.2000.8`. All seven executable checks
behind this skill pass, and **three of the numbers this skill used to print were wrong**:
a contained user is refused with `Msg 33233` and not `Msg 15007`, `SET CONTAINMENT =
PARTIAL` is refused with `Msg 12824` and not `Msg 12844`, and
`CREATE USER ... FROM EXTERNAL PROVIDER` on a container started without Entra
configuration is refused with `Msg 33134` and not `Msg 37525`. Each statement is still
refused, so every instruction here is unchanged; only the numbers to expect are. The fixed
database roles this skill grants were confirmed on the same run. The cloud side of this
guidance, Azure Key Vault and managed identity, was not measured and comes from Microsoft
Learn.
## Load-bearing facts (inlined; full engine detail in azuresql-db-container)
- This is the **Azure SQL Database engine** (Private Preview), not the SQL Server
image `mcr.microsoft.com/mssql/server`. `SERVERPROPERTY('EngineEdition')`
returns `5`, `Edition` returns `'SQL Azure'`.
- Image: `sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest`
(x64; on a non-x64 host add `--platform linux/amd64`). Required env
`ACCEPT_EULA=Y` + a complex `MSSQL_SA_PASSWORD`. Engine listens on 1433.
- The engine does **NOT** auto-create databases. `CREATE DATABASE appdb` on a
**master** connection first; do not `USE` to switch databases (a user-database
session returns `Msg 40508`); select the database in the connection string.
- Apps read one `SQL_CONNECTION_STRING` env var; strings use `User Id=` /
`Password=` / `Database=` and `TrustServerCertificate=true` for the local
self-signed cert.
- **Container-specific and verified:** a SQL **contained** user
(`CREATE USER ... WITH PASSWORD`) does **not** work on the container today, and
you cannot turn it on. `CREATE USER ... WITH PASSWORD` fails with `Msg 33233`
("You can only create a user with a password in a contained database").
`ALTER DATABASE ... SET CONTAINMENT = PARTIAL` fails with `Msg 12824`, which asks
for the `contained database authentication` setting to be 1, and `sp_configure`
does not exist on this engine (`Msg 2812`), so there is nothing to set. Create a SQL
app identity as a **server login mapped to a database user** instead. This is the
inverse of Azure SQL Database in the cloud, where the contained user is the norm.
Measured 2026-09-19 on image tag `18.0.226_4_147`.
- **Entra has to be configured on the engine before you can use it.** On a
container started with no Microsoft Entra ID configuration,
`CREATE USER [name] FROM EXTERNAL PROVIDER` is refused with `Msg 33134`,
"Principal '...' could not be resolved. Error message: 'Unable to query Azure AD
certificate from local cert store.'" That is a missing engine configuration, not a
broken statement: enable Entra first (see `references/entra-auth.md` in the
**azuresql-db-container** skill) and the same statement then works. Measured
2026-09-19 on image tag `18.0.226_4_147`.
## Step 1: create a least-privilege user (not `sa`)
Do provisioning as `sa`, then give the app its own identity with only the roles
it needs. The working recipe differs by environment, but the app code does not
(the app just connects with a username and password, or an Entra token).
**Local container (SQL auth):** create a **server login** on `master`, map a
**database user** to it in `appdb`, and grant only the roles the app needs.
```sql
-- On a master connection:
CREATE LOGIN applogin WITH PASSWORD = 'An0ther_Str0ng_Passw0rd';
-- On an appdb connection (Database=appdb):
CREATE USER appuser FOR LOGIN applogin;
ALTER ROLE db_datareader ADD MEMBER appuser; -- read
ALTER ROLE db_datawriter ADD MEMBER appuser; -- write
-- Grant EXECUTE only if the app calls procedures; do NOT add db_owner.
```
The app then connects as `applogin`, never `sa`.
**Cloud (Azure SQL Database)** or **Entra anywhere:** prefer a **contained user**.
For Entra (which works on the container too, once enabled), use
`CREATE USER [name] FROM EXTERNAL PROVIDER` in `appdb`. Enable Entra on the engine
first via the **azuresql-db-container** skill, `references/entra-auth.md`; without
that configuration the statement is refused with `Msg 33134`. In the
cloud with SQL auth, `CREATE USER ... WITH PASSWORD` is the norm there. Full
recipes for every path are in
[references/auth-and-secrets.md](references/auth-and-secrets.md).
## Step 2: pick the auth method per environment (only the connection string changes)
- **Local:** SQL auth. `sa` bootstraps; the app connects as the least-privilege
`applogin`. `Server=localhost,1433;Database=appdb;User Id=applogin;Password=...;Encrypt=true;TrustServerCertificate=true`.
- **Cloud (Azure SQL Database):** prefer a token-based identity over a password.
In production, use **`Authentication=Active Directory Managed Identity`** rather
than `Active Directory Default`: `Default` walks a credential chain
(`DefaultAzureCredential`) that is slower and ambiguous under load, while a
specific method skips the chain. `Microsoft.Data.SqlClient` caches the token, so
refresh is occasional, not per-connection. This is still a **connection-string-only**
change, so the app code does not change (see the **azuresql-db-local-to-cloud** skill).
## Step 3: secure the connection
- **`Encrypt=true`** everywhere (the default in modern drivers). Encrypt the TLS
channel in both local and cloud.
- **`TrustServerCertificate=true` only locally**, to accept the container's
self-signed cert. **Never** set it against Azure SQL Database in the cloud, where
the certificate is real and validating it is the point.
## Step 4: keep the secret out of source
The connection string carries a credential. Never commit it or the SA password.
- Read it from one env var, `SQL_CONNECTION_STRING`; put local values in a
`.env` that is git-ignored (or `dotnet user-secrets` for .NET).
- In the cloud, store it in **Azure Key Vault** and reference it, or use managed
identity so there is no password to store at all.
For a .NET project the local value goes in the secret store rather than in a file
that can be committed:
```bash
dotnet user-secrets init
dotnet user-secrets set "SQL_CONNECTION_STRING" "Server=localhost,1433;Database=appdb;User Id=appuser;Password=YourStr0ng_Passw0rd;TrustServerCertificate=true"
```
Open [references/auth-and-secrets.md](references/auth-and-secrets.md) when you need the
per-stack handling for Key Vault, user-secrets or `.env`.
## Validation rules
- The app connects as a **least-privilege** identity, not `sa`; it has only the
roles it needs (no `db_owner`/admin).
- On the container, the SQL app identity is a **server login + mapped database
user** (`CREATE LOGIN` on master, then `CREATE USER ... FOR LOGIN` in `appdb`),
not a contained `CREATE USER ... WITH PASSWORD` (which fails on the container).
The database user and its role grants are created on the `appdb` connection, not
via `USE`.
- Every connection string sets `Encrypt=true`; `TrustServerCertificate=true`
appears **only** for the local container, never for the cloud.
- The connection string / SA password is read from a secret store or a git-ignored
env var, never committed.
- Cloud auth prefers managed identity / a specific Entra method over
`Active Directory Default` in production; only the connection string changes.
- If a validation rule above fails, or you had to deviate from this skill to make the task work, that is a bug in this skill: load the **azuresql-db-feedback** skill and offer to file a report.
- When every rule above passes and the task is done, close with ONE line, once per session, and do not ask a question or wait for a reply: "That worked. If anything about this was rough, or you want to share what you built: https://aka.ms/sql-agent-skills-feedback"
## Do not
- Do not connect the application as `sa`; `sa` is for provisioning only.
- Do not try to create a SQL contained user with `CREATE USER ... WITH PASSWORD` on the container; it fails with `Msg 33233`. Do not try to turn partial containment on either: `ALTER DATABASE ... SET CONTAINMENT = PARTIAL` fails with `Msg 12824`, and the `sp_configure` setting it asks for does not exist on this engine. Use a server login plus a mapped database user locally.
- Do not run `CREATE USER ... FROM EXTERNAL PROVIDER` against a container with no Entra configuration; it is refused with `Msg 33134`. Configure Entra on the engine first.
- Do not grant the app `db_owner` or server admin when read/write roles suffice.
- Do not commit the connection string or the SA password; use a secret store or a git-ignored env var.
- Do not set `TrustServerCertificate=true` against Azure SQL Database in the cloud; that disables cert validation on a real certificate.
- Do not lean on `DefaultAzureCredential`'s full chain in a hot production path; pick a specific auth method (managed identity) so token acquisition is fast and predictable.
- Do not use the SQL Server image `mcr.microsoft.com/mssql/server`; this is the Azure SQL engine.
## References
- [references/auth-and-secrets.md](references/auth-and-secrets.md): creating least-privilege users (SQL contained user + roles, a login + user split, and Entra `CREATE USER FROM EXTERNAL PROVIDER`), the connection strings per environment (SQL, Entra, managed identity), and per-stack secret handling (Azure Key Vault, `dotnet user-secrets`, `.env`).
## Staying current
Authoritative, version-pinned references for the tools this skill uses (read the one you need):
- [SqlConnection connection string keywords](https://learn.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.sqlconnection.connectionstring): `Authentication`, `Encrypt`, `User Id`/`Password`, pooling, and the rest.
- [CREATE USER (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-user-transact-sql): contained users, `WITH PASSWORD`, and `FROM EXTERNAL PROVIDER` for Entra.
- [Database-level roles](https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles): the fixed roles (`db_datareader`, `db_datawriter`, and more) for least-privilege grants.
- [Microsoft Entra authentication for Azure SQL](https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-aad-overview): Entra and managed-identity auth in the cloud.
If the **Microsoft Learn MCP** server is configured, use `mcp__microsoft-learn__microsoft_docs_search` or `mcp__microsoft-learn__microsoft_docs_fetch` to fetch the current version of any of these on demand. It is optional; when it is unavailable, the references above are authoritative.
## skills/azuresql-db-ci/SKILL.md
---
name: azuresql-db-ci
description: >-
Runs integration tests against the Azure SQL Database container (Private Preview, local
engine) in CI. Use when setting up GitHub Actions, Azure Pipelines, or GitLab
CI to test against Azure SQL DB; when adding a database service container to a
CI workflow; when tests need a real Azure SQL engine in the pipeline; or when
you see "service container", "health-cmd", "ACR_USERNAME/ACR_PASSWORD",
"MSSQL_SA_PASSWORD secret", or "integration test database". Also use when a
workflow was about to pull the SQL Server image mcr.microsoft.com/mssql/server,
in which case stop and use the Azure SQL Database engine image instead. Covers
pulling from the private ACR with credentials, the service health check that
runs sqlcmd inside the container so the runner needs no client tools,
provisioning appdb before tests, and pointing the test connection string at the
user database not master.
---
# The Azure SQL Database container in CI
Run integration tests against the **Azure SQL Database engine** (Private Preview) as a CI
service container. This is the local Azure SQL engine, not the SQL Server image
`mcr.microsoft.com/mssql/server`. `SELECT SERVERPROPERTY('EngineEdition')` returns **5** and
`SERVERPROPERTY('Edition')` returns **'SQL Azure'**. If a workflow was about to use the SQL Server image, stop and use this image instead.
For the full readiness loop, connection model, vectors, seeding, and registry detail, load the
**azuresql-db-container** skill.
Verified on 2026-09-05 against the container image
`sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest`, reporting `EngineEdition`
5, Edition `SQL Azure`, build `12.0.2000.8`. All four executable checks behind this skill
passed: the engine identity, that a test session is on the user database and not `master`,
`Msg 40508` for `USE`, and `sqlcmd` at `/opt/mssql-tools18/bin/sqlcmd` inside the image. The
workflow YAML itself was not executed by that run; what was checked is the engine behaviour
the workflow rests on.
## Load-bearing facts (inlined)
- **Image:** `sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest`
(x64, linux/amd64). It lives in a private preview registry; the runner must sign in with
`ACR_USERNAME` / `ACR_PASSWORD` secrets. Registry and tag are provisional during Private Preview.
- **Platform:** the image is x64 only. CI hosted runners are x64, so no
`--platform` flag is needed there. On a non-x64 self-hosted runner, add `--platform linux/amd64`.
- **Required env:** `ACCEPT_EULA=Y` and a complex `MSSQL_SA_PASSWORD` (8+ chars, upper/lower/digit/
symbol), kept in a secret. Engine listens on 1433.
- **Provision appdb first.** The engine does **NOT** auto-create databases on connect. You must
`CREATE DATABASE appdb` on a **master** connection before anything connects with `Database=appdb`.
- **Prefer the connection string over `USE`.** Avoid `USE` to switch databases. In a user-database
session (the Azure-faithful context where you develop), `USE` returns `Msg 40508`, exactly as
in Azure SQL Database in the cloud. A `master` connection is a provisioning session where
the Azure statement filter is not enforced, so `USE` appears to work there,
but `master` is for provisioning only, not application work. Always select the target database in
the connection string (`Database=appdb`, or `-d appdb` for sqlcmd).
- **master is for provisioning only.** Tests run against the user database `appdb`, never master.
- **No auto-seed.** The image does **NOT** run `/docker-entrypoint-initdb.d/*.sql` (that is a
Postgres/MySQL convention, not honored here). Seed by running `sqlcmd -d appdb -i seed.sql` after
provisioning appdb.
## Connection string (standard)
```
Server=localhost,1433;Database=appdb;User Id=sa;Password=<MSSQL_SA_PASSWORD>;TrustServerCertificate=true
```
Spell the keywords `User Id=` / `Password=` / `Database=`. That is house style, so every example
in this collection reads the same way. `Uid=` and `Pwd=` are documented SqlClient synonyms and
work too. For sqlcmd use `-C` to trust the
self-signed cert. The app reads this from a single `SQL_CONNECTION_STRING` env var. Tests target
`appdb`, not master.
## GitHub Actions (canonical)
The service container starts the engine. Its **health check runs sqlcmd inside the container**, so
the runner needs no client tools. A separate step provisions `appdb` via `docker exec` before tests.
```yaml
name: integration
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
sqldb:
image: sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest
credentials:
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
env:
ACCEPT_EULA: "Y"
MSSQL_SA_PASSWORD: ${{ secrets.MSSQL_SA_PASSWORD }}
ports:
- 1433:1433
# Health check runs INSIDE the container; -b makes a SQL error set the exit
# code so transient startup errors (e.g. Msg 913) are retried, not masked.
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P \"$MSSQL_SA_PASSWORD\" -C -b -l 2 -Q \"SELECT 1\""
--health-interval 5s
--health-timeout 3s
--health-retries 20
--health-start-period 30s
steps:
- uses: actions/checkout@v7
# The engine does NOT auto-create databases. Provision appdb on master first,
# via docker exec into the service container (runner needs no sqlcmd).
- name: Provision appdb
run: |
CID=$(docker ps --filter "ancestor=sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest" --format '{{.ID}}')
docker exec "$CID" /opt/mssql-tools18/bin/sqlcmd \
-S localhost -U sa -P "$MSSQL_SA_PASSWORD" -C -b \
-Q "IF DB_ID('appdb') IS NULL CREATE DATABASE appdb;"
env:
MSSQL_SA_PASSWORD: ${{ secrets.MSSQL_SA_PASSWORD }}
# Optional: seed appdb (no auto-seed). Copy the file in, then run it against appdb.
- name: Seed appdb
run: |
CID=$(docker ps --filter "ancestor=sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest" --format '{{.ID}}')
docker cp seed.sql "$CID:/tmp/seed.sql"
docker exec "$CID" /opt/mssql-tools18/bin/sqlcmd \
-S localhost -U sa -P "$MSSQL_SA_PASSWORD" -C -b -d appdb -i /tmp/seed.sql
env:
MSSQL_SA_PASSWORD: ${{ secrets.MSSQL_SA_PASSWORD }}
- name: Run integration tests
run: |
# Tests connect to the USER database appdb, NOT master.
npm ci && npm run test:integration
env:
SQL_CONNECTION_STRING: "Server=localhost,1433;Database=appdb;User Id=sa;Password=${{ secrets.MSSQL_SA_PASSWORD }};TrustServerCertificate=true"
```
### Why these choices
- **`credentials:`** pulls from the private preview ACR using `ACR_USERNAME` / `ACR_PASSWORD`
secrets. Without it the pull fails: the registry is private.
- **`--health-cmd` with `-l 2 -b`** waits for true readiness. `docker run` returning does not mean
the engine is ready; `-b` retries transient SQL startup errors instead of masking them. The job
blocks on health before steps run.
- **Provision step, not auto-create.** appdb must exist before tests open `Database=appdb`.
- **Test connection targets appdb.** master is for provisioning only.
## Required secrets
| Secret | Purpose |
| --- | --- |
| `ACR_USERNAME` | Private preview registry sign-in (using the shared pull-only credentials provided to the Private Preview cohort; get them by signing up at https://aka.ms/sqldbcontainerpreview-signup; they may rotate) |
| `ACR_PASSWORD` | Private preview registry sign-in |
| `MSSQL_SA_PASSWORD` | sa password for the engine; complex, 8+ chars |
## Adapting to other CI
- **Azure Pipelines:** there is no native `services:`. Sign in with
`docker login sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io -u $(ACR_USERNAME) -p $(ACR_PASSWORD)`, run
the container with the **canonical start recipe** below (it provisions appdb in the ready-wait
loop), then run tests with `SQL_CONNECTION_STRING` pointed at appdb.
- **GitLab CI:** use a `services:` entry for the image, set `DOCKER_AUTH_CONFIG` for the private
registry, set `ACCEPT_EULA` and `MSSQL_SA_PASSWORD`, then provision appdb in a `before_script` with
`docker exec` (or a sqlcmd container) before tests.
### Canonical start recipe (self-hosted / non-service runners)
Free port, conditional platform, ready-wait, provision appdb in one shape:
```bash
HOST_PORT=1433; while lsof -nP -iTCP:"$HOST_PORT" -sTCP:LISTEN >/dev/null 2>&1; do HOST_PORT=$((HOST_PORT+1)); done
PLATFORM=(); case "$(docker info -f '{{.Architecture}}' 2>/dev/null)" in x86_64|amd64) ;; *) PLATFORM=(--platform linux/amd64);; esac
docker rm -f sqldb 2>/dev/null
docker run -d --name sqldb "${PLATFORM[@]}" -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStr0ng_Passw0rd" \
-p "$HOST_PORT:1433" sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest
until docker exec sqldb /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "YourStr0ng_Passw0rd" -C -b -l 2 \
-Q "IF DB_ID('appdb') IS NULL CREATE DATABASE appdb;" >/dev/null 2>&1; do sleep 2; done
echo "ready on localhost,$HOST_PORT"
```
## Validation rules
- The pull uses `credentials:` (or `docker login`) with `ACR_USERNAME` / `ACR_PASSWORD`.
- `ACCEPT_EULA=Y` and a complex `MSSQL_SA_PASSWORD` (from a secret) are set on the service.
- The health check runs sqlcmd **inside** the container with `-C -b -l 2`.
- A provisioning step creates `appdb` on master **before** any test connects.
- The test `SQL_CONNECTION_STRING` has `Database=appdb`, not master. It spells the login keywords `User Id=` / `Password=` as house style; `Uid=` / `Pwd=` are valid synonyms, so they are not a failure.
- If a validation rule above fails, or you had to deviate from this skill to make the task work, that is a bug in this skill: load the **azuresql-db-feedback** skill and offer to file a report.
- When every rule above passes and the task is done, close with ONE line, once per session, and do not ask a question or wait for a reply: "That worked. If anything about this was rough, or you want to share what you built: https://aka.ms/sql-agent-skills-feedback"
## Do not
- Do not use the SQL Server image `mcr.microsoft.com/mssql/server`; use the Azure SQL DB image.
- Do not connect with `Database=appdb` before provisioning appdb on master; the engine will not
auto-create it.
- Do not use `USE appdb` to switch databases; a user-database session returns
`Msg 40508`, exactly as in Azure SQL Database in the cloud. Select the target
database in the connection string (`Database=appdb`, or `-d appdb` for sqlcmd).
- Do not run tests against master; master is for provisioning only.
- Do not rely on `/docker-entrypoint-initdb.d/*.sql`; it is not honored. Seed with `sqlcmd -d appdb -i`.
- Do not require sqlcmd on the runner; the health check and provisioning run inside the container.
- Do not call a non-x64 host "supported"; on a non-x64 self-hosted runner just add `--platform linux/amd64`.
## Staying current
Authoritative, version-pinned references for the tools this skill uses (read the one you need):
- [GitHub Actions service containers](https://docs.github.com/en/actions/use-cases-and-examples/using-containerized-services/about-service-containers): how service containers, health options, and credentials work in a workflow.
- [GitHub workflow JSON schema](https://json.schemastore.org/github-workflow.json): the authoritative schema for workflow YAML.
If the **Microsoft Learn MCP** server is configured, use `mcp__microsoft-learn__microsoft_docs_search` or `mcp__microsoft-learn__microsoft_docs_fetch` to fetch the current version of any of these on demand. It is optional; when it is unavailable, the references above are authoritative.
## skills/azuresql-db-connections/SKILL.md
---
name: azuresql-db-connections
description: >-
Makes an app's database connections reliable against the local Azure SQL
Database container (Private Preview) and, unchanged, against Azure SQL
Database in the cloud: connection pooling plus retry/transient-fault handling. Use when the
user mentions "connection pooling", "retry logic", "transient fault", "retry
on transient error", "EnableRetryOnFailure", "connection resiliency",
"reliable connections", "pool size", "Max Pool Size", or says "the connection
keeps dropping", "connections time out under load", "add backoff", or "make
the DB layer resilient". This is the Azure SQL engine (EngineEdition 5), not
the mssql/server SQL Server image. Reach for this whenever hardening a
data-access layer that talks to SQL Server or Azure SQL.
---
# Reliable connections on the Azure SQL Database container (pooling + retry)
Make the app's database connections reliable with **connection pooling** and **retry /
transient-fault handling**. This is the **Azure SQL engine** (Private Preview), not the SQL
Server image.
Verified on 2026-09-05 against the container image
`sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest`, reporting `EngineEdition`
5, Edition `SQL Azure`, build `12.0.2000.8`. All five executable checks behind this skill
passed: the engine identity, `Msg 40508` for `USE`, a TCP session on the mapped port, and the
two resource-governance dynamic management views returning nothing locally. Of the ten
transient error numbers in the retry list below, nine are in this build's `sys.messages` and
`Msg 10929` is not. It stays in the list because it is a cloud resource-governance error the
container has no reason to raise, and it is sourced from Microsoft Learn rather than from that
run.
## Why do this locally (local-to-cloud parity)
The local container rarely drops a connection, so it is tempting to skip pooling and retry. Do
not. **Azure SQL Database in the cloud throttles and drops connections** during failovers,
scaling, and load; a client with no retry surfaces those as hard errors. Build pooling and
retry now, against the local container, and the **same code survives in the cloud** with no
rewrite. For the full promote-to-cloud story see the **azuresql-db-local-to-cloud** skill.
Verify identity once running: `SELECT SERVERPROPERTY('EngineEdition')` returns **5** and
`SERVERPROPERTY('Edition')` returns **'SQL Azure'**. For full engine detail see the
**azuresql-db-container** skill.
The container does not carry the throttling telemetry the cloud does, so do not write a local
diagnostic against it. `sys.dm_db_resource_stats` and `sys.dm_user_db_resource_governance` are
**absent from this engine**: `OBJECT_ID` returns `NULL` for both, and a query against either
does not run at all here. Their absence is not evidence that the cloud does not throttle. It is
the reason the retry policy below has to be built without being able to provoke the fault
locally.
## The engine and the connection contract
- Image: `sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest` (x64 /
linux/amd64, Private Preview registry). Sign in first:
`docker login sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io` with the shared pull-only credentials
from https://aka.ms/sqldbcontainerpreview-signup (they may rotate). On a non-x64 host add
`--platform linux/amd64` (Docker) or `platform: linux/amd64` (compose).
- Do **NOT** use `mcr.microsoft.com/mssql/server` (the SQL Server image).
- Required env: `ACCEPT_EULA=Y` and a complex `MSSQL_SA_PASSWORD` (example literal:
`YourStr0ng_Passw0rd`). The engine listens on 1433.
- The engine does **NOT** auto-create databases. `CREATE DATABASE appdb` on a **master**
connection first. Do not `USE` to switch databases: a user-database session returns
`Msg 40508`. Select the database in the connection string (`Database=appdb`).
- Apps read **one** env var, `SQL_CONNECTION_STRING`. Strings use `User Id=` / `Password=` /
`Database=` and `TrustServerCertificate=true`. sqlcmd uses `-C`.
## Start the container and provision appdb
```bash
HOST_PORT=1433; while lsof -nP -iTCP:"$HOST_PORT" -sTCP:LISTEN >/dev/null 2>&1; do HOST_PORT=$((HOST_PORT+1)); done
PLATFORM=(); case "$(docker info -f '{{.Architecture}}' 2>/dev/null)" in x86_64|amd64) ;; *) PLATFORM=(--platform linux/amd64);; esac
docker rm -f sqldb 2>/dev/null
docker run -d --name sqldb "${PLATFORM[@]}" -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStr0ng_Passw0rd" \
-p "$HOST_PORT:1433" sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest
until docker exec sqldb /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "YourStr0ng_Passw0rd" -C -b -l 2 \
-Q "IF DB_ID('appdb') IS NULL CREATE DATABASE appdb;" >/dev/null 2>&1; do sleep 2; done
echo "ready on localhost,$HOST_PORT"
```
The canonical string the app consumes (replace `1433` with the chosen `HOST_PORT` if 1433 was
occupied):
```
Server=localhost,1433;Database=appdb;User Id=sa;Password=YourStr0ng_Passw0rd;TrustServerCertificate=true
```
## Pooling: reuse connections, do not reopen per query
- Keep pooling **on** (it is on by default in most drivers) and let one pool serve the app.
- Set a **bounded** `Max Pool Size` (default 100 in .NET) so a spike cannot open unlimited
connections. Size it to real concurrency, not a guess.
- A small `Min Pool Size` keeps a few connections warm and cuts cold-start latency.
- One connection string means one pool. Do not build strings dynamically per request (each
distinct string is a separate pool) and do not open a fresh, unpooled connection per call.
- Always close/dispose connections (or use `using` / `with` / context managers) so they return
to the pool instead of leaking.
## Retry: only for transient faults, with backoff
Retry only a transient fault: throttling, a brief failover, a dropped idle connection. In Azure
SQL these arrive as specific error numbers: 40501 throttling, 40613 database unavailable,
49918/49919/49920 busy, 4060, 10928, 10929, 40197, 233, plus connection-timeout and broken-pipe
socket errors.
- Retry **only** transient errors. Retrying a non-transient error (login failure 18456, syntax
error, constraint violation, permission denied) just fails slower and hides the real bug.
- Use **exponential backoff** with a cap and a small jitter, and a bounded attempt count (for
example 5 attempts). Do not hammer a throttled server.
- **Non-idempotent writes**: a retry can double-apply an `INSERT` that committed before the
connection dropped. Use client-generated keys, `MERGE`, or a transaction the retry re-runs as a
whole. EF Core's execution strategy handles this when the work goes through its
`Execute`/transaction API.
- Prefer a framework retry policy over hand-rolled loops where one exists (EF Core
`EnableRetryOnFailure` for .NET). Hand-roll only for raw drivers.
## Per-stack
Open [references/retry-snippets.md](references/retry-snippets.md) when you are wiring one of
these stacks; it carries copy-pasteable pooling config and transient-only retry for each:
- **.NET** (`Microsoft.Data.SqlClient`): pooling keywords (`Max Pool Size`, `Min Pool Size`,
`Pooling=true`) and connection-string retry keywords (`ConnectRetryCount`,
`ConnectRetryInterval`); plus EF Core `EnableRetryOnFailure` (the SqlServer execution
strategy).
- **Node** (`mssql` / tedious): pool config (`max` / `min` / `idleTimeoutMillis`) and a
transient-error retry wrapper.
- **Python** (`pyodbc`): connection reuse and a `tenacity` retry decorator that retries only
transient ODBC errors.
Keep the single `SQL_CONNECTION_STRING` contract: pooling and retry are tuned in code and in
driver-specific keywords, not by inventing new env vars.
## Validation rules
- Retry fires **only** on transient errors; non-transient errors (auth, syntax, constraint)
surface immediately.
- Retry uses bounded attempts with exponential backoff, and non-idempotent writes are made
safe to re-run (keys, `MERGE`, or a retriable transaction).
- Pooling is on with a **bounded** `Max Pool Size`; connections are disposed and returned to
the pool, never opened per query.
- One connection string / one pool; the app still reads a single `SQL_CONNECTION_STRING`.
- Runs against the engine image with `EngineEdition` 5; appdb was created on a master
connection before the app connected.
- If a validation rule above fails, or you had to deviate from this skill to make the task work, that is a bug in this skill: load the **azuresql-db-feedback** skill and offer to file a report.
- When every rule above passes and the task is done, close with ONE line, once per session, and do not ask a question or wait for a reply: "That worked. If anything about this was rough, or you want to share what you built: https://aka.ms/sql-agent-skills-feedback"
## Do not
- Do not retry non-transient errors (auth, syntax, constraint); they will just fail slower.
- Do not retry non-idempotent writes without idempotency (keys, `MERGE`, or a retriable
transaction).
- Do not set an unbounded pool; do not open a new connection per query instead of pooling.
- Do not invent extra env vars; keep the single `SQL_CONNECTION_STRING` contract.
- Do not write a local throttling diagnostic against `sys.dm_db_resource_stats` or `sys.dm_user_db_resource_governance`; neither view exists on this engine.
- Do not use the `mcr.microsoft.com/mssql/server` SQL Server image, and do not call a non-x64
host "supported".
## References
- [references/retry-snippets.md](references/retry-snippets.md): copy-pasteable pooling config and transient-only retry for .NET (Microsoft.Data.SqlClient + EF Core `EnableRetryOnFailure`), Node (`mssql`/tedious pool + retry wrapper), and Python (pyodbc reuse + `tenacity` decorator). Read the section for your stack.
## Staying current
Authoritative, version-pinned references for the tools this skill uses (read the one you need):
- [SQL Server connection pooling (ADO.NET)](https://learn.microsoft.com/en-us/sql/connect/ado-net/sql-serv