You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure API Management中GraphQL SQL数据库解析器无法工作,求排查原因

问题描述

我正在Azure API Management中为GraphQL API配置SQL Database Resolver,测试时返回解析错误,具体信息如下:

定义的Schema

type Query {
  getUsers: UserList!
}

type User {
  id: ID!
  name: String!
  age: Int!
}

type UserList {
  items: [User!]!
}

配置的Resolver

<sql-data-source>
    <connection-info>
        <connection-string use-managed-identity="true">
            Server=tcp:my-sqlserver.windows.net,1433;Initial Catalog=my-sqldb;
        </connection-string>
    </connection-info>
    <request>
        <sql-statement>
            SELECT
                u.id
                u.name
                u.age
            FROM
                users u
        </sql-statement>
    </request>
    <response />
</sql-data-source>

测试返回的错误响应

{
  "errors": [
    {
      "message": "Error trying to resolve field 'getUsers'.",
      "locations": [
        {
          "line": 2,
          "column": 2
        }
      ],
      "path": [
        "getUsers"
      ],
      "extensions": {
        "code": "FILE_NOT_FOUND",
        "codes": [
          "FILE_NOT_FOUND"
        ]
      }
    }
  ],
  "data": null
}

跟踪信息中的错误详情

Could not load file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' or one of its dependencies. The system cannot find the file specified.
问题原因及解决方向
  1. 核心原因:Azure API Management的运行时环境缺少指定版本(5.0.0.0)的Microsoft.Data.SqlClient程序集,导致无法加载SQL客户端依赖完成数据库连接操作。
  2. 场景细分:
    • 若使用托管APIM服务,可能是当前服务层级的运行时未预装该版本程序集,或版本不兼容;
    • 若使用自托管网关,需检查网关部署的服务器/容器环境中是否安装了对应版本的Microsoft.Data.SqlClient依赖包;
  3. 额外语法问题:Resolver中的SQL查询语句存在错误——SELECT后的字段u.id、u.name、u.age之间缺少逗号分隔,需修正为:
    SELECT
        u.id,
        u.name,
        u.age
    FROM
        users u
    

内容的提问来源于stack exchange,提问作者javasparrow769

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 16:33:26