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

如何通过Power Automate/HTTP/PowerShell自动配置带本地网关的SQL连接?

问题

需要在Power Platform组织的多个环境中创建带本地数据网关的SQL Server连接,遇到以下问题:

  • 使用Power Automate Management的「Create Connection」动作时,无法配置本地数据网关参数,创建后也无法补充配置
  • 尝试直接调用https://management.azure.com/providers/Microsoft.PowerApps/apis/shared_flowmanagement的CreateConnection操作,发送指定请求体后,持续收到「action on scope apis is disallowed」错误,用PowerShell或OAuth2.0 Bearer令牌认证均无法解决

可行的解决方案

1. 修正HTTP调用的端点与请求体

你之前使用的全局端点不支持网关配置,需改用环境级别的连接创建端点,具体配置如下:

  • 端点URL:https://management.azure.com/providers/Microsoft.PowerApps/environments/{environment-id}/connections?api-version=2016-11-01
  • 请求方法:PUT
  • 认证:使用具备Microsoft.PowerApps/connections/write权限的Azure AD Bearer令牌
  • 正确请求体示例:
{
  "properties": {
    "api": {
      "id": "/providers/Microsoft.PowerApps/apis/shared_sql"
    },
    "displayName": "SQL Server 自动连接",
    "parameterValues": {
      "server": "{servername}",
      "database": "{db name}",
      "authType": "SQL Server Authentication",
      "username": "{SQL username}",
      "password": "{password}",
      "gatewayId": "{gateway-resource-id}"
    }
  },
  "location": "eastus"
}

注:gatewayId需替换为你的本地数据网关资源ID,可通过Power Platform管理中心或API https://management.azure.com/providers/Microsoft.PowerApps/gateways?api-version=2016-11-01 查询获取

2. 替代方法:用PowerShell模块批量创建

使用Microsoft.PowerApps.Administration.PowerShell模块可更便捷地批量创建带网关的连接:

  • 安装模块:
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force
  • 登录Power Platform:
Add-PowerAppsAccount
  • 创建连接命令示例:
$gateway = Get-AdminPowerAppGateway -GatewayName "{你的网关名称}"
New-AdminPowerAppConnection `
  -EnvironmentName "{目标环境ID}" `
  -ConnectorName "shared_sql" `
  -ConnectionName "SQL-Auto-Conn" `
  -ConnectionProperties @{
    server = "{servername}"
    database = "{db name}"
    authType = "SQL Server Authentication"
    username = "{SQL username}"
    password = "{password}"
    gatewayId = $gateway.Id
  }

3. 权限要求

无论采用哪种方式,执行账号需满足:

  • 目标Power Platform环境的环境管理员角色
  • Azure AD中已分配Microsoft.PowerApps/connections/write权限(可通过自定义Azure AD角色配置)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 22:52:47