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

Azure SQL调用外部API遇31612错误,求解决方案

解决Azure SQL Database调用sp_invoke_external_rest_endpoint时的域名限制问题

你遇到的Msg 31612错误,是因为Azure SQL Database默认限制第三方域名的出站访问,而Restrict Outbound Networking功能未启用时,无法通过添加规则放行目标域名。以下是具体解决步骤:

1. 启用Restrict Outbound Networking功能

  • 登录Azure门户,定位到你的Azure SQL Server(注意是服务器级别,不是单个数据库)
  • 进入网络设置,切换到出站网络规则标签页
  • 开启Restrict outbound networking开关(启用后默认会拒绝所有出站访问,需立即添加允许规则)

2. 添加允许date.nager.at的出站规则

  • 在出站网络规则页面点击添加出站规则
  • 填写规则名称(例如Allow_DateNager_API)
  • 目标类型选择FQDN,输入date.nager.at
  • 操作设置为允许,保存规则

3. 验证规则生效

等待1-5分钟让规则同步生效,重新执行你的SQL代码即可正常调用API。

额外注意事项

  • 该功能仅支持vCore购买模型的Azure SQL Database,如果你的数据库是DTU模型,需要升级到vCore,或者通过Azure Function中转API请求(SQL调用Function,Function再调用目标API)
  • 确保目标API使用HTTPS协议,sp_invoke_external_rest_endpoint不支持HTTP请求
  • 如果目标域名对应多个IP,使用FQDN规则会自动解析并放行所有关联IP,比添加单个IP更可靠

你的SQL代码示例:

DECLARE @URL NVARCHAR(255) = 'https://date.nager.at/api/v3/PublicHolidays/2024/ZA'

DECLARE @HR INT;
DECLARE @JSONResponse as NVARCHAR(max);

EXEC @HR = sp_invoke_external_rest_endpoint
     @url = @URL,
     @method = 'GET',
     @response = @JSONResponse output;

SELECT @HR AS ReturnCode, @JSONResponse AS Response

错误提示:
Msg 31612, Level 16, State 1, Procedure sys.sp_invoke_external_rest_endpoint_internal, Line 1 Connections to the domain date.nager.at are not allowed

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 22:08:27