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

调用Data API Builder存储过程REST API时遇Primary key未配置错误

解决Data API Builder存储过程REST API的主键配置错误

问题原因

Data API Builder(DAB)要求所有返回结果集的数据库对象(包括存储过程)必须配置主键——用来唯一标识结果集中的每条记录。即便存储过程本身没有定义主键,只要返回的结果集包含唯一标识字段(比如你的Id),就需要在DAB配置中明确指定。

解决方案

在PageCustomers配置块中添加primary-key字段,指定结果集中的主键字段(此处为Id):

修改后的完整配置:

"PageCustomers": {
  "source": {
    "type": "stored-procedure",
    "object": "[dbo].[PageCustomers]",
    "parameters": {
      "PageSize": "",
      "StartIndex": ""
    }
  },
  "permissions": [
    {
      "role": "anonymous",
      "actions": [
        "execute"
      ]
    }
  ],
  "primary-key": ["Id"], // 新增主键配置
  "mappings": {
    "Id": "Id",
    "Name": "Name",
    "City": "City",
    "State": "State"
  },
  "rest": {
    "path": "/pagecustomers",
    "methods": [
      "get"
    ]
  },
  "graphql": {
    "operation": "mutation"
  }
},

额外注意事项

  • 确保URL参数与存储过程参数匹配:你的请求URL用的是pagesize和index,但配置里的存储过程参数是PageSize和StartIndex。可以调整URL参数名,或者修改DAB的REST路径定义来映射参数:
    "rest": {
      "path": "/pagecustomers/pagesize/{PageSize}/index/{StartIndex}",
      "methods": ["get"]
    }
    
    这样请求URL就能正确关联到存储过程的参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 07:42:58