故障排除 'A network-related or instance-specific error occurred while establishing a connection to SQL Server' 连接到 Azure SQL 服务器

Troubleshooting 'A network-related or instance-specific error occurred while establishing a connection to SQL Server' connecting to Azure SQL Server

背景:

我使用 EFCore (2.2.2) 创建了一个 .Net Core (2.2.0) 应用程序。到目前为止,我一直在使用本地 SQL 服务器实例,并试图改用 Azure SQL 服务器。

我已将数据库上下文中的连接字符串更新为在 Azure 仪表板上找到的连接字符串。

我已经在 VS2017 的 SQL 服务器对象资源管理器中登录到 Azure 中使用的帐户,并且正在显示数据库。

我使用的是代码优先方法,因此在 运行 应用程序之前没有可用的表。

错误:

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: SQL Network Interfaces, error: 25 - Connection string is not valid)

连接字符串是:

.UseSqlServer(
            @"Server = tcp:db.database.windows.net, 1433;
              Initial Catalog = DB;
              Persist Security Info = False;
              User ID = username@db.database.windows.net;
              Password = password; 
              MultipleActiveResultSets = False; Encrypt = True; 
              TrustServerCertificate = false; 
              Connection Timeout = 60;");

我的本地网络没有很好的功能。这会对连接产生影响吗?

或者是这个连接字符串有误?

编辑:我将连接超时更改为 800 秒,大约 800 秒后连接再次超时,这次的错误略有不同:

错误 2:

A network-related or '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.)'

您可能没有提供从安全组远程连接到您的 Azure 数据库的权限。大多数情况下,不允许从远程计算机访问它。从数据库安全组和资源安全组检查并确保您的 IP 在允许列表中。

我要关闭它,因为这是一个延迟问题。