排查 Azure SQL 数据库的连接问题Troubleshoot connection issues to Azure SQL Database

与 Azure SQL 数据库连接失败时,会收到错误消息When the connection to Azure SQL Database fails, you receive error messages. 本文是一个集中介绍对 Azure SQL 数据库连接问题进行故障排除的主题。This article is a centralized topic that helps you troubleshoot Azure SQL Database connectivity issues. 本文介绍连接问题的常见原因,推荐可帮助确定问题的故障排除工具,还提供解决暂时性错误持久或非暂时性错误的故障排除步骤。It introduces the common causes of connection issues, recommends a troubleshooting tool that helps you identity the problem, and provides troubleshooting steps to solve transient errors and persistent or non-transient errors.

如果遇到连接问题,请尝试本文中介绍的故障排除步骤。If you encounter the connection issues, try the troubleshoot steps that are described in this article.

如果本文未解决你的 Azure 问题,请访问 MSDN 和 CSDN 上的 Azure 论坛。If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and CSDN. 可以在这些论坛上发布问题。You can post your issue in these forums. 还可提交 Azure 支持请求。You also can submit an Azure support request. 若要提交支持请求,请在 Azure 支持页上提交。To submit a support request, on the Azure support page.

原因Cause

连接问题可能由以下任何原因引起:Connection problems may be caused by any of the following:

  • 在应用程序设计过程中无法应用最佳实践和设计准则。Failure to apply best practices and design guidelines during the application design process. 请参阅 SQL 数据库开发概述了解入门信息。See SQL Database Development Overview to get started.
  • Azure SQL 数据库重新配置Azure SQL Database reconfiguration
  • 防火墙设置Firewall settings
  • 连接超时Connection time-out
  • 不正确的登录信息Incorrect login information
  • 一些 Azure SQL 数据库资源达到最大限制Maximum limit reached on some Azure SQL Database resources

通常,Azure SQL 数据库的连接问题可按如下方式分类:Generally, connection issues to Azure SQL Database can be classified as follows:

尝试使用 Azure SQL 数据库连接问题的故障排除工具Try the troubleshooter for Azure SQL Database connectivity issues

如果遇到特定的连接错误,请尝试使用 此工具,以帮助快速识别并解决问题。If you encounter a specific connection error, try this tool, which will help you quickly identity and resolve your problem.

对暂时性错误进行故障排除Troubleshoot transient errors

当应用程序连接到 Azure SQL 数据库时,你会收到以下错误消息:When an application connects to an Azure SQL database, you receive the following error message:

Error code 40613: "Database <x> on server <y> is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of <z>"

Note

此错误消息通常是暂时的(生存期较短)。This error message is typically transient (short-lived).

当数据库正在移动(或重新配置),且应用程序与数据库断开连接时,会出现此错误。This error occurs when the database is being moved (or reconfigured) and your application loses its connection to the database. 之所以会发生数据库重新配置事件是因为,有计划内事件(例如,软件升级)或计划外事件(例如,进程故障或负载均衡)。Database reconfiguration events occur because of a planned event (for example, a software upgrade) or an unplanned event (for example, a process crash, or load balancing). 大多数重新配置事件的生存期通常较短,应在最多 60 秒内完成。Most reconfiguration events are generally short-lived and should be completed in less than 60 seconds at most. 但是,这些事件偶尔可能需要更长时间才能完成,例如当大型事务导致长时间运行的恢复时。However, these events can occasionally take longer to finish, such as when a large transaction causes a long-running recovery.

解决暂时性连接问题的步骤Steps to resolve transient connectivity issues

  1. 检查 Azure 服务仪表板在由应用程序报告错误期间是否发生任何已知的服务中断。Check the Azure Service Dashboard for any known outages that occurred during the time during which the errors were reported by the application.
  2. 连接到云服务的应用程序(如 Azure SQL 数据库)应期望定期重新配置事件并实施重试逻辑来处理这些错误,而不是将它们作为应用程序错误展现给用户。Applications that connect to a cloud service such as Azure SQL Database should expect periodic reconfiguration events and implement retry logic to handle these errors instead of surfacing these as application errors to users. 查看暂时性错误部分和 SQL 数据库开发概述中的最佳实践和设计准则以了解更多信息和常规重试策略。Review the Transient errors section and the best practices and design guidelines at SQL Database Development Overview for more information and general retry strategies. 然后,请参阅 SQL 数据库和 SQL Server 的连接库 中的代码示例,了解具体细节。Then, see code samples at Connection Libraries for SQL Database and SQL Server for specifics.
  3. 由于数据库即将达到其资源限制,因此错误看起来像是暂时性连接问题。As a database approaches its resource limits, it can seem to be a transient connectivity issue. 请参阅资源限制See Resource limits.
  4. 如果连接问题继续存在,或者应用程序发生错误的持续时间超过 60 秒或在特定的一天中看到错误多次发生,请通过在 Azure 支持网站上选择“获取支持”提出 Azure 支持请求。If connectivity problems continue, or if the duration for which your application encounters the error exceeds 60 seconds or if you see multiple occurrences of the error in a given day, file an Azure support request by selecting Get Support on the Azure Support site.

排查一再出现的错误Troubleshoot persistent errors

如果应用程序一直无法连接到 Azure SQL 数据库,通常表示下列其中一项出现了问题:If the application persistently fails to connect to Azure SQL Database, it usually indicates an issue with one of the following:

  • 防火墙配置。Firewall configuration. Azure SQL 数据库或客户端防火墙阻止了与 Azure SQL 数据库的连接。The Azure SQL database or client-side firewall is blocking connections to Azure SQL Database.
  • 客户端上重新配置了网络:例如,使用了新的 IP 地址或代理服务器。Network reconfiguration on the client side: for example, a new IP address or a proxy server.
  • 用户失误:例如,连接参数(例如连接字符串中的服务器名称)键入错误。User error: for example, mistyped connection parameters, such as the server name in the connection string.

解决永久性连接问题的步骤Steps to resolve persistent connectivity issues

  1. 设置防火墙规则以允许客户端 IP 地址。Set up firewall rules to allow the client IP address. 若要进行临时测试,可设置一项防火墙规则,使用 0.0.0.0 作为起始 IP 地址范围,使用 255.255.255.255 作为结束 IP 地址范围。For temporary testing purposes, set up a firewall rule using 0.0.0.0 as the starting IP address range and using 255.255.255.255 as the ending IP address range. 这样会使服务器向所有 IP 地址开放。This will open the server to all IP addresses. 如果这样可以解决连接性问题,请删除此规则,再针对适当限制的 IP 地址或地址范围创建防火墙规则。If this resolves your connectivity issue, remove this rule and create a firewall rule for an appropriately limited IP address or address range.
  2. 在客户端与 Internet 之间的所有防火墙上,确保为出站连接打开端口 1433。On all firewalls between the client and the Internet, make sure that port 1433 is open for outbound connections. 有关需要为 Azure Active Directory 身份验证打开的其他端口的其他信息,请查看配置 Windows 防火墙以允许 SQL Server 访问混合标识所需的端口和协议Review Configure the Windows Firewall to Allow SQL Server Access and Hybrid Identity Required Ports and Protocols for additional pointers related to additional ports that you need to open for Azure Active Directory authentication.
  3. 验证连接字符串和其他连接设置。Verify your connection string and other connection settings. 请参阅连接问题主题中的“连接字符串”部分。See the Connection String section in the connectivity issues topic.
  4. 在仪表板中检查服务运行状况。Check service health in the dashboard. 如果认为存在区域性的中断,请参阅从中断恢复,了解恢复到新区域的步骤。If you think there's a regional outage, see Recover from an outage for steps to recover to a new region.

后续步骤Next steps

其他资源Additional resources