【问题标题】:Azure Runbook to connect to SQL server running on Azure VMAzure Runbook 连接到在 Azure VM 上运行的 SQL 服务器
【发布时间】:2019-06-11 08:19:37
【问题描述】:

我正在尝试使用以下示例代码(已定义 SQL 用户名和密码)连接到在 Azure VM 上运行的 SQL 服务器:

$SqlCredential = Get-AutomationPSCredential -Name $SqlCredentialAsset 

# Get the username and password from the SQL Credential 
$SqlUsername = $SqlCredential.UserName 
$SqlPass = $SqlCredential.GetNetworkCredential().Password 

# Define the connection to the SQL Database 
$Conn = New-Object System.Data.SqlClient.SqlConnection("Server=tcp:$SqlServer,$SqlServerPort;Database=$Database;User ID=$SqlUsername;Password=$SqlPass;Trusted_Connection=False;Encrypt=True;")

此代码在我连接到 Azure SQL 数据库时有效,但在连接到在 Azure VM 上运行的 SQL 时无效。

抛出的错误是:

Error occured: Exception calling "Open" with "0" argument(s): 
"A network-related or instance-specific error occurred while establishing a 
connection to SQL Server. The server was not found or was not accessible.
 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 
(provider: TCP Provider, error: 0 - No such host is known.)"

我已在 VM 上验证了 SQL 远程连接已启用并包括定义的 TCP 端口 1433。

【问题讨论】:

    标签: azure azure-automation azure-runbook


    【解决方案1】:

    可能是网络相关问题。如果您已在 VM 上验证了 SQL 远程连接已启用并包括定义的 TCP 端口 1433。此外,1433 端口在连接到 VM 的 NSG 的入站端口规则和 VM 内的 windows 防火墙中打开。您可以使用telnet 在本地验证此端口。

    此外,您可以指定 $SqlServer= "sqlvmlabel.eastus.cloudapp.azure.com",这是 Azure VM 的公共 DNS 名称。下面是使用 SQL 身份验证的连接字符串示例。

    Server=sqlvmlabel.eastus.cloudapp.azure.com;Integrated Security=false;User ID=<login_name>;Password=<your_password>
    

    阅读更多信息:connect to a SQL Server Virtual Machine on Azure

    【讨论】:

      猜你喜欢
      • 2019-11-06
      • 1970-01-01
      • 2017-08-31
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      相关资源
      最近更新 更多