【发布时间】: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