如何从二头肌调用的脚本中使用天蓝色专用端点?

问题描述 投票:0回答:1

我有一个二头肌,它使用专用终结点创建 Azure SQL。然后我使用此资源 Microsoft.Resources/deploymentScripts@2020-10-01 来运行连接到 Azure Sql 的 PowerShell 脚本。

它失败了,因为它正在尝试使用公共端点。我如何强制它使用专用端点?

我收到此错误: 使用“0”个参数调用“Open”时出现异常:

“原因:建立实例时发生特定于实例的错误 连接到 SQL Server。由于拒绝公开,连接被拒绝 网络访问设置为是 (https://docs.microsoft.com/azure/azure-sql/database/connectivity-settings#deny-public-network-access)。 要连接到此服务器,请使用您的内部的专用端点 虚拟网络 (https://docs.microsoft.com/azure/sql-database/sql-database-private-endpoint-overview#how-to-set-up-private-link-for-azure-sql-database)。 ”

azure azure-sql-database azure-virtual-network azure-bicep
1个回答
0
投票
  1. 运行

    Test-NetConnection
    返回详细的连接信息,包括建立连接所需的时间 或者您可以使用
    Resolve-DnsName
    Powershell 命令查询专用端点的 DNS 名称服务器。

  2. 更改

    connection string
    脚本中的
    PowerShell
    以包含专用端点 URL。通过参考MSDoc,我为SQL数据库创建了一个私有端点,在
    script content
    块中添加了以下部署脚本,并能够成功部署它。

resource runPowerShellInline 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
....
properties: {
 scriptContent: '''
      $serverName = sqlServerName
      $database = databaseName
      $privateEndpointURL = "sqlServerName.privatelink.database.windows.net"
      $connString = "Server=$privateEndpointURL;Database=databaseName;User Id=sqlAdministratorLogin;Password=sqlAdministratorLoginPassword;"
      $SQLconnection = New-Object System.Data.SqlClient.SqlConnection
      $SQLconnection.ConnectionString = $connString
      $SQLconnection.Open()
   '''
  }
}
    

部署:

az deployment group create --resource-group "Jahnavi" --template-file script.bicep

门户视图部署:

enter image description here

如果问题仍然存在,请检查

PowerShell
脚本是否在虚拟网络上下文中运行。如果您从与 Azure SQL 数据库的专用端点位于同一虚拟网络上的 Azure VM 运行部署脚本,它应该按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.