从 Azure DevOps 管道访问 SQL 服务器

Accessing SQL Server from Azure DevOps Pipeline

问题

我已经设置了一个 Azure 管道,我遇到的问题是在管道的测试程序集部分失败,因为它无法解析连接 string/find 我的 SQL 服务器.

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception: The network path was not found

在这种情况下,我想避免创建模拟,理想情况下让代码直接与 SQL 服务器通信。

SQL 服务器位于 Azure VM 上,因此它不是 'Azure SQL Database' 服务。

我试过的

我已经打开 Azure VM 上的端口以允许来自 Azure DevOps 使用的所有 regions/IP 范围的流量(我在网上发现这是必需的)。我还尝试将管道 'Test Assemblies' 内的连接字符串指向不同的(本地)windows 服务器,该服务器包含 SQL 服务器的实例,但它仍然无法 find/connect 到 SQL.

从我的本地(Azure VM 和本地服务器)连接到 SQL 时,我可以连接。我们还有一些其他服务使用位于 Azure VM 上的 SQL 服务器,因此我相信连接问题与从 Azure Pipeline 连接有关。

以前有人遇到过这个问题吗?

更新

我已更新连接字符串以直接引用端口,即

**.***.**.***,1433

并且错误消息现在已更改为:

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 - The wait operation timed out.) ---> System.ComponentModel.Win32Exception: The wait operation timed out

我现在可以使用了。

在将 Azure DevOps 区域从西欧更改为英国南部后,我的 DevOps 现在可以与我 VM 上的 SQL 服务器通信(根据 Leo Liu-MSFT 的评论,所需的 IP 地址已列入白名单) .