azuresql-db-dab
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInstant REST + GraphQL API on the Azure SQL Database container with Data API Builder
使用 Data API Builder 在 Azure SQL Database 容器上即时提供 REST + GraphQL API
Generate a full REST and GraphQL API over the local Azure SQL Database container
(Private Preview) with no application code, using Data API Builder (DAB) -
Microsoft's first-party open-source engine. You describe tables as entities in
; DAB serves them. DAB connects over the normal TDS protocol
with a plain connection string, so no change tracking or special engine
feature is needed.
dab-config.jsonThe generated keeps the environment-variable indirection rather than the
password, the and prefixes and the endpoint are defaults, and REST and
GraphQL return the same rows from a table in the container.
dab-config.json/api/graphql/mcp通过 Data API Builder(DAB)——Microsoft 的第一方开源引擎,无需应用程序代码,
即可为本地 Azure SQL Database 容器(私有预览版)生成完整的 REST 和 GraphQL API。
你可以在 中将表定义为实体;DAB 会对外提供这些实体。DAB 使用普通连接字符串
通过常规 TDS 协议连接,因此无需变更跟踪或特殊引擎功能。
dab-config.json生成的 通过环境变量间接引用密码,而不是直接保存密码; 和 前缀以及 端点均为默认值,且 REST 和 GraphQL 会返回容器中同一张表的相同数据行。
dab-config.json/api/graphql/mcpScope
范围
- Prefer this over hand-writing a controller or ORM API when the user only needs REST or GraphQL over existing tables, even when they just say "give me an API for this database".
- The MCP endpoint is an API surface DAB serves from the database, not a separate SQL MCP server.
- What a configuration publishes and to whom (roles, row policies, generated entities, a managed
identity in Azure) is .
dab-rest-and-graphql
- 当用户只需要基于现有表使用 REST 或 GraphQL 时,应优先采用此方案,而不是手写 controller 或 ORM API,即使用户只说“给我这个数据库一个 API”也可以。
- MCP 端点是由 DAB 从数据库提供的 API 界面,而不是独立的 SQL MCP server。
- 配置会发布什么以及向谁发布(角色、行策略、生成的实体、Azure 中的托管身份)由 skill 负责。
dab-rest-and-graphql
Load-bearing facts (inlined; full engine detail in azuresql-db-container)
关键事实(已内联;完整引擎细节见 azuresql-db-container
skill)
azuresql-db-container- This is the Azure SQL Database engine (Private Preview), not the SQL Server
image .
mcr.microsoft.com/mssql/serverreturnsSERVERPROPERTY('EngineEdition'),5returnsSERVERPROPERTY('Edition').'SQL Azure' - Image: (x64,
sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest). Registry is private: sign in first withlinux/amd64using the shared pull-only credentials from https://aka.ms/sqldbcontainerpreview-signup (they may rotate). Registry and tag are provisional during Private Preview.docker login sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io - Required env: and a unique, caller-supplied complex
ACCEPT_EULA=Y(8+ chars, upper/lower/digit/symbol). Engine listens on 1433.MSSQL_SA_PASSWORD - The engine does NOT auto-create databases. Run on a master connection before DAB connects with
CREATE DATABASE appdb. Do not useDatabase=appdbto switch databases (in a user-database session it returnsUSE); select the database in the connection string.Msg 40508 - On a non-x64 host add .
--platform linux/amd64
For the full engine model (readiness loop, vectors, troubleshooting) see the
azuresql-db-container skill. To start the container and provision
first, use azuresql-db-container or azuresql-db-scaffold.
appdb- 这是 Azure SQL Database 引擎(私有预览版),而不是 SQL Server 镜像 。
mcr.microsoft.com/mssql/server返回SERVERPROPERTY('EngineEdition'),5返回SERVERPROPERTY('Edition')。'SQL Azure' - 镜像:(x64,
sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest)。注册表为私有:先使用 https://aka.ms/sqldbcontainerpreview-signup 提供的共享仅拉取凭据执行linux/amd64(凭据可能会轮换)。私有预览期间,注册表和标签均为暂定值。docker login sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io - 必需环境变量:,以及由调用方提供、符合复杂度要求的唯一
ACCEPT_EULA=Y(至少 8 个字符,包含大写/小写字母/数字/符号)。引擎监听 1433 端口。MSSQL_SA_PASSWORD - 引擎不会自动创建数据库。在 DAB 使用 连接之前,需在 master 连接上运行
Database=appdb。不要使用CREATE DATABASE appdb切换数据库(在用户数据库会话中会返回USE);应在连接字符串中选择数据库。Msg 40508 - 在非 x64 主机上,添加 。
--platform linux/amd64
有关完整的引擎模型(就绪循环、向量、故障排查),请参阅 azuresql-db-container skill。要先启动容器并预配 ,请使用 azuresql-db-container 或 azuresql-db-scaffold。
appdbStep 1: install DAB
第 1 步:安装 DAB
Two supported ways. Pick the CLI for local dev; pick the container to wire DAB
into a compose stack. Open references/dab-snippets.md when you want
that compose service rather than the CLI.
bash
undefined有两种受支持的方式。本地开发请选择 CLI;需要将 DAB 接入 Compose 技术栈时请选择容器。需要该 Compose 服务而非 CLI 时,请打开 references/dab-snippets.md。
bash
undefinedCLI (.NET 8 required): installs the dab
command. 2.1.5 is the release this skill and its siblings
dabCLI (.NET 8 required): installs the dab
command. 2.1.5 is the release this skill and its siblings
dab(dab-rest-and-graphql, dab-mcp-endpoint, deploy-dab-to-azure) were checked on; move all four together.
(dab-rest-and-graphql, dab-mcp-endpoint, deploy-dab-to-azure) were checked on; move all four together.
dotnet tool install --global Microsoft.DataApiBuilder --version 2.1.5
dotnet tool install --global Microsoft.DataApiBuilder --version 2.1.5
later: dotnet tool update --global Microsoft.DataApiBuilder --version <new>
later: dotnet tool update --global Microsoft.DataApiBuilder --version <new>
Container image (alternative):
Container image (alternative):
mcr.microsoft.com/azure-databases/data-api-builder:2.1.5
mcr.microsoft.com/azure-databases/data-api-builder:2.1.5
undefinedundefinedStep 2: point DAB at the container over one env var
第 2 步:通过一个环境变量将 DAB 指向容器
DAB reads the complete, caller-supplied through
, so no secret is written into . Use the host port your
container chose.
SQL_CONNECTION_STRING@env()dab-config.jsonBuild it from the same caller-supplied password and host port used by the SQL
container:
bash
set +x
: "${MSSQL_SA_PASSWORD:?Set MSSQL_SA_PASSWORD to the SQL container password}"
: "${HOST_PORT:?Set HOST_PORT to the SQL container host port}"
SQL_CONNECTION_STRING="Server=localhost,$HOST_PORT;Database=appdb;User Id=sa;"
SQL_CONNECTION_STRING+="Password=$MSSQL_SA_PASSWORD;TrustServerCertificate=true"
export SQL_CONNECTION_STRINGTrustServerCertificate=trueappdbdab startbash
for i in $(seq 1 60); do
sqlcmd -S "localhost,$HOST_PORT" -U sa -P "$MSSQL_SA_PASSWORD" -C -d master -Q "SELECT 1" >/dev/null 2>&1 && break
sleep 2
done
sqlcmd -S "localhost,$HOST_PORT" -U sa -P "$MSSQL_SA_PASSWORD" -C -d master \n -Q "IF DB_ID('appdb') IS NULL CREATE DATABASE appdb;"Without this, logs and exits. A readiness
check alone does not fix that; the database has to be created.
dab startCannot open database "appdb" requested by the loginDAB 通过 读取由调用方提供的完整 ,因此无需将机密写入 。请使用容器选择的宿主机端口。
@env()SQL_CONNECTION_STRINGdab-config.json使用 SQL 容器所用的相同调用方密码和宿主机端口进行构建:
bash
set +x
: "${MSSQL_SA_PASSWORD:?Set MSSQL_SA_PASSWORD to the SQL container password}"
: "${HOST_PORT:?Set HOST_PORT to the SQL container host port}"
SQL_CONNECTION_STRING="Server=localhost,$HOST_PORT;Database=appdb;User Id=sa;"
SQL_CONNECTION_STRING+="Password=$MSSQL_SA_PASSWORD;TrustServerCertificate=true"
export SQL_CONNECTION_STRINGTrustServerCertificate=trueappdbdab startbash
for i in $(seq 1 60); do
sqlcmd -S "localhost,$HOST_PORT" -U sa -P "$MSSQL_SA_PASSWORD" -C -d master -Q "SELECT 1" >/dev/null 2>&1 && break
sleep 2
done
sqlcmd -S "localhost,$HOST_PORT" -U sa -P "$MSSQL_SA_PASSWORD" -C -d master \
-Q "IF DB_ID('appdb') IS NULL CREATE DATABASE appdb;"否则, 会记录 并退出。仅执行就绪检查无法解决此问题;必须实际创建数据库。
dab startCannot open database "appdb" requested by the loginStep 3: init, add entities, start
第 3 步:初始化、添加实体并启动
bash
undefinedbash
undefinedInitialize config in Development mode (enables Swagger + friendlier errors).
Initialize config in Development mode (enables Swagger + friendlier errors).
dab init --database-type mssql
--connection-string "@env('SQL_CONNECTION_STRING')"
--host-mode Development
--connection-string "@env('SQL_CONNECTION_STRING')"
--host-mode Development
dab init --database-type mssql
--connection-string "@env('SQL_CONNECTION_STRING')"
--host-mode Development
--connection-string "@env('SQL_CONNECTION_STRING')"
--host-mode Development
Expose a table as an entity. Repeat per table.
Expose a table as an entity. Repeat per table.
--permissions is role:actions; "anonymous:*" allows all actions with no auth (dev only).
--permissions is role:actions; "anonymous:*" allows all actions with no auth (dev only).
dab add Book --source dbo.Books --source.type table --permissions "anonymous:*"
dab add Book --source dbo.Books --source.type table --permissions "anonymous:*"
Serve REST + GraphQL (and the MCP endpoint) on loopback only.
Serve REST + GraphQL (and the MCP endpoint) on loopback only.
ASPNETCORE_URLS=http://127.0.0.1:5000 dab start
`appdb` is just the example database name and `Book`/`dbo.Books` the example
entity/table; substitute your own. The entity name (`Book`) is what appears in
the API path; the `--source` is the real `schema.table`. The `anonymous:*`
permission is only for this loopback local demonstration.ASPNETCORE_URLS=http://127.0.0.1:5000 dab start
`appdb` 只是示例数据库名称,`Book`/`dbo.Books` 是示例实体/表,请替换为你自己的名称。实体名称(`Book`)会出现在 API 路径中;`--source` 才是实际的 `schema.table`。`anonymous:*` 权限仅用于这个 loopback 本地演示。Step 4: use the API
第 4 步:使用 API
With running (default port 5000):
dab start- REST: (list),
GET http://localhost:5000/api/Book(by key), plus/api/Book/id/1/POST/PATCH/PUT. Query withDELETE,?$filter=,$select=,$orderby=,$first=(OData-style).$after= - GraphQL: - queries and mutations for every entity, with relationship navigation.
POST http://localhost:5000/graphql - OpenAPI / Swagger: (document) and
GET /api/openapi(UI, Development mode only).GET /swagger - Health: .
GET /health
bash
curl http://localhost:5000/api/Book
curl -s http://localhost:5000/graphql -H 'Content-Type: application/json' \
-d '{"query":"{ books { items { id title } } }"}'dab start- REST: (列表)、
GET http://localhost:5000/api/Book(按 key 查询),以及/api/Book/id/1/POST/PATCH/PUT。可使用DELETE、?$filter=、$select=、$orderby=、$first=查询(OData 风格)。$after= - GraphQL: ——为每个实体提供 query 和 mutation,并支持关系导航。
POST http://localhost:5000/graphql - OpenAPI / Swagger: (文档)和
GET /api/openapi(UI,仅限 Development 模式)。GET /swagger - 健康检查: 。
GET /health
bash
curl http://localhost:5000/api/Book
curl -s http://localhost:5000/graphql -H 'Content-Type: application/json' \
-d '{"query":"{ books { items { id title } } }"}'Relationships, config detail
关系与配置详情
DAB exposes related entities (e.g. an author's books) once you declare the
relationship. Config schema, permissions/policies, , REST/GraphQL
options, and the exact syntax are in
references/dab-config-reference.md; open it when declaring a
relationship or changing permissions, policies, or API options.
@env()dab update --relationship声明关系后,DAB 就会公开相关实体(例如某位作者的作品)。配置 schema、权限/策略、、REST/GraphQL 选项以及 的确切语法见 references/dab-config-reference.md;声明关系或更改权限、策略、API 选项时,请打开该文档。
@env()dab update --relationshipMCP endpoint (a DAB feature, not a separate SQL MCP server)
MCP 端点(DAB 功能,不是独立的 SQL MCP server)
DAB 2.x (checked on 2.1.5) also serves a built-in MCP endpoint
from the same , at by default,
enabled by default. This is an additional API surface Data API Builder provides
over your configured entities - it is not, and should not be presented as, a
standalone "MSSQL MCP server." How to point an MCP client at it and how to
scope the exposed tools is in references/dab-mcp.md; open it when a user
asks to point an MCP client at DAB, or to narrow which entities it exposes.
REST, GraphQL, and MCP use the same entity permissions. Once the endpoint is
hosted rather than on loopback, connecting a remote client, its authentication
and tool curation belong to dab-mcp-endpoint, and hosting DAB in Azure to
deploy-dab-to-azure.
dab-config.jsonhttp://localhost:5000/mcpDAB 2.x(基于 2.1.5 验证)还会通过同一份 提供内置 MCP 端点,默认地址为 ,且默认启用。这是 Data API Builder 在已配置实体之上提供的附加 API 界面——它不是,也不应被描述为独立的 "MSSQL MCP server." 如何将 MCP client 指向该端点,以及如何限定所暴露工具的范围,见 references/dab-mcp.md;当用户要求将 MCP client 指向 DAB,或需要缩小其公开的实体范围时,请打开该文档。
dab-config.jsonhttp://localhost:5000/mcpREST、GraphQL 和 MCP 使用相同的实体权限。一旦端点已托管而不再仅在 loopback 上运行,连接远程 client、其身份验证和工具范围界定分别属于 dab-mcp-endpoint,而将 DAB 托管到 Azure 则属于 deploy-dab-to-azure。
Validation rules
验证规则
- The database engine is the container image above (EngineEdition=5), never
.
mcr.microsoft.com/mssql/server - exists (created on a master connection) BEFORE
appdb; DAB's connection string usesdab startandDatabase=appdb.TrustServerCertificate=true - The connection string is supplied via , not hardcoded into
@env('SQL_CONNECTION_STRING').dab-config.json - An local demonstration listens only on
anonymous:*.127.0.0.1 - serves REST at
dab startand GraphQL at/api/<Entity>; a/graphqlon the entity returns rows from the container.GET - If you present the MCP endpoint, it is described as a DAB-provided API surface, not a standalone SQL MCP server.
- 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"
- 数据库引擎必须是上述容器镜像(EngineEdition=5),绝不能使用 。
mcr.microsoft.com/mssql/server - 必须在
appdb之前通过 master 连接创建;DAB 的连接字符串使用dab start和Database=appdb。TrustServerCertificate=true - 连接字符串必须通过 提供,不能硬编码到
@env('SQL_CONNECTION_STRING')中。dab-config.json - 本地演示只能监听
anonymous:*。127.0.0.1 - 在
dab start提供 REST,在/api/<Entity>提供 GraphQL;对实体执行/graphql会返回容器中的数据行。GET - 如果介绍 MCP 端点,必须将其描述为 DAB 提供的 API 界面,而不是独立的 SQL MCP server。
- 如果上述任一验证规则失败,或你不得不偏离此 skill 才能完成任务,则说明此 skill 存在缺陷:加载 azuresql-db-feedback skill,并主动提出提交报告。
- 当上述所有规则均通过且任务完成时,每个会话仅以以下一行结束,不要提问或等待回复:"运行成功。如果其中有任何不顺利之处,或者你想分享你构建的内容:https://aka.ms/sql-agent-skills-feedback"
Check it worked
检查是否成功
- Positive verification: Request one enabled REST or GraphQL endpoint and confirm the expected status, schema, and row payload.
- Cleanup verification: Stop DAB, remove its generated configuration, container, and network, and confirm no generated secret files remain.
- Report success only after both observations pass.
- 正向验证: 请求一个已启用的 REST 或 GraphQL 端点,并确认预期状态、schema 和数据行 payload。
- 清理验证: 停止 DAB,删除其生成的配置、容器和网络,并确认没有残留生成的机密文件。
- 只有在两项观察均通过后才能报告成功。
Do not
禁止事项
- Do not use the SQL Server image ; this is the Azure SQL engine.
mcr.microsoft.com/mssql/server - Do not expect DAB to create ; provision it on a master connection first.
appdb - Do not recommend removing or recreating the SQL container to get a clean state; create idempotently on a master connection instead, and say plainly when a step destroys data.
appdb - Do not hardcode the connection string (or the SA password) into ; use
dab-config.json.@env('SQL_CONNECTION_STRING') - Do not make remotely reachable. A shared service requires token validation or an authenticating gateway that blocks direct DAB access, with scoped permissions;
anonymous:*is not shared-service authentication.Simulator - Do not describe DAB's MCP endpoint as a standalone Microsoft SQL MCP server; it is an API surface DAB provides.
- Do not drop (the container uses a self-signed cert) or
TrustServerCertificate=trueon a non-x64 host.--platform linux/amd64
- 不要使用 SQL Server 镜像 ;这是 Azure SQL 引擎。
mcr.microsoft.com/mssql/server - 不要期望 DAB 创建 ;应先通过 master 连接进行预配。
appdb - 不要建议删除或重建 SQL 容器来获得干净状态;应改为通过 master 连接以幂等方式创建 ,并在任何会破坏数据的步骤发生时明确说明。
appdb - 不要将连接字符串(或 SA 密码)硬编码到 中;请使用
dab-config.json。@env('SQL_CONNECTION_STRING') - 不要让 可从远程访问。共享服务需要使用 token 验证,或使用可阻止直接访问 DAB 的身份验证网关,并配置范围化权限;
anonymous:*不是共享服务的身份验证机制。Simulator - 不要将 DAB 的 MCP 端点描述为独立的 Microsoft SQL MCP server;它是 DAB 提供的 API 界面。
- 不要省略 (容器使用自签名证书),也不要在非 x64 主机上省略
TrustServerCertificate=true。--platform linux/amd64
References
参考文档
- references/dab-config-reference.md: open it when editing , connection handling, entities, permissions, policies, API settings, or relationships.
dab-config.json - references/dab-snippets.md: open it when you need a copyable CLI, container, compose, REST, or GraphQL recipe.
- references/dab-mcp.md: open it when enabling or scoping DAB's built-in MCP endpoint or connecting an MCP client.
- references/dab-config-reference.md:编辑 、处理连接、管理实体、权限、策略、API 设置或关系时打开。
dab-config.json - references/dab-snippets.md:需要可直接复制的 CLI、容器、Compose、REST 或 GraphQL 示例时打开。
- references/dab-mcp.md:需要启用或限定 DAB 内置 MCP 端点,或者连接 MCP client 时打开。
Staying current
保持最新
Authoritative, version-pinned references for the tools this skill uses (read the one you need):
- Data API Builder configuration reference: every config key (data-source, runtime, entities, autoentities), with examples.
- DAB config JSON schema (pinned v2.1.5): the machine-readable schema checks against, and the one
dab validate2.1.5 writes intodab init. Bump this URL together with the CLI version above.dab-config.json - Data API Builder built-in MCP endpoint: the built-in MCP endpoint, DML tools, transports, and RBAC.
If the Microsoft Learn MCP server is configured, use or to fetch the current version of any of these on demand. It is optional; when it is unavailable, the references above are authoritative.
mcp__microsoft-learn__microsoft_docs_searchmcp__microsoft-learn__microsoft_docs_fetch本 skill 使用的工具的权威、版本固定参考文档(按需读取):
- Data API Builder 配置参考:涵盖所有配置项(data-source、runtime、entities、autoentities),并提供示例。
- DAB config JSON schema(固定为 v2.1.5):这是 检查时使用的机器可读 schema,也是
dab validate2.1.5 写入dab init的 schema。更新此 URL 时,应与上方的 CLI 版本同步更新。dab-config.json - Data API Builder 内置 MCP 端点:介绍内置 MCP 端点、DML 工具、传输方式和 RBAC。
如果已配置 Microsoft Learn MCP server,请使用 或 按需获取上述文档的当前版本。这是可选项;不可用时,以上参考文档即为权威来源。
mcp__microsoft-learn__microsoft_docs_searchmcp__microsoft-learn__microsoft_docs_fetch