排查 Azure SQL 数据库和 Azure SQL 托管实例的连接问题和其他问题Troubleshooting connectivity issues and other errors with Azure SQL Database and Azure SQL Managed Instance

适用于:是 Azure SQL 数据库 是Azure SQL 托管实例 APPLIES TO: yesAzure SQL Database yesAzure SQL Managed Instance

与 Azure SQL 数据库或 Azure SQL 托管实例连接失败时,你会收到错误消息。You receive error messages when the connection to Azure SQL Database or Azure SQL Managed Instance fails. 连接问题可能由以下原因导致:重新配置、防火墙设置、连接超时、登录信息不正确,或无法在应用程序设计过程中应用最佳做法和设计准则。These connection problems can be caused by reconfiguration, firewall settings, a connection timeout, incorrect login information or failure to apply best practices and design guidelines during the application design process. 此外,如果达到了某些 Azure SQL 数据库或 SQL 托管实例资源的最大限制,则无法再连接。Additionally, if the maximum limit on some Azure SQL Database or SQL Managed Instance resources is reached, you can no longer connect.

暂时性故障错误消息(40197、40613 等)Transient fault error messages (40197, 40613 and others)

Azure 基础结构能够在 SQL 数据库服务中出现大量工作负荷时动态地重新配置服务器。The Azure infrastructure has the ability to dynamically reconfigure servers when heavy workloads arise in the SQL Database service. 此动态行为可能会导致客户端程序失去其与数据库或实例的连接。This dynamic behavior might cause your client program to lose its connection to the database or instance. 此类错误情况称为 暂时性故障This kind of error condition is called a transient fault. 之所以会发生数据库重新配置事件是因为,有计划内事件(例如,软件升级)或计划外事件(例如,进程故障或负载均衡)。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. 下表列出了在连接到 SQL 数据库时应用程序可能会收到的各种暂时性错误The following table lists various transient errors that applications can receive when connecting to SQL Database

暂时性故障错误代码的列表List of transient fault error codes

错误代码Error code 严重性Severity 说明Description
40604060 1616 无法打开该登录请求的数据库“%.*ls”。Cannot open database "%.*ls" requested by the login. 登录失败。The login failed. 有关详细信息,请参阅错误 4000 到 4999For more information, see Errors 4000 to 4999
4019740197 1717 该服务在处理你的请求时遇到错误。The service has encountered an error processing your request. 请重试。Please try again. 错误代码 %d。Error code %d.

当服务由于软件或硬件升级、硬件故障或任何其他故障转移问题而关闭时,将收到此错误。You receive this error when the service is down due to software or hardware upgrades, hardware failures, or any other failover problems. 错误 40197 的消息中嵌入的错误代码 (%d) 提供有关所发生的故障或故障转移类型的其他信息。The error code (%d) embedded within the message of error 40197 provides additional information about the kind of failure or failover that occurred. 错误 40197 的消息中嵌入的错误代码的一些示例有 40020、40143、40166 和 40540。Some examples of the error codes are embedded within the message of error 40197 are 40020, 40143, 40166, and 40540.

重新连接会将你自动连接到数据库的正常运行副本。Reconnecting automatically connects you to a healthy copy of your database. 应用程序必须捕获错误 40197、记录该消息中嵌入的错误代码 (%d) 以供进行故障排除,然后尝试重新连接到 SQL 数据库,直到资源可用且再次建立连接为止。Your application must catch error 40197, log the embedded error code (%d) within the message for troubleshooting, and try reconnecting to SQL Database until the resources are available, and your connection is established again. 有关详细信息,请参阅暂时性错误For more information, see Transient errors.
4050140501 20 个20 服务当前正忙。The service is currently busy. 请在 10 秒钟后重试请求。Retry the request after 10 seconds. 事件 ID:%ls。Incident ID: %ls. 代码:%d。Code: %d. 有关详细信息,请参阅:For more information, see:
•  逻辑 SQL Server 资源限制•  Logical SQL server resource limits
•  单一数据库的基于 DTU 的限制•  DTU-based limits for single databases
•  弹性池的基于 DTU 的限制•  DTU-based limits for elastic pools
•  单一数据库的基于 vCore 的限制•  vCore-based limits for single databases
•  弹性池的基于 vCore 的限制•  vCore-based limits for elastic pools
•  Azure SQL 托管实例资源限制•  Azure SQL Managed Instance resource limits.
4061340613 1717 数据库“%.*ls”(在服务器“%.*ls”上)当前不可用。Database '%.*ls' on server '%.*ls' is not currently available. 请稍后重试连接。Please retry the connection later. 如果问题仍然存在,请与客户支持人员联系,并向其提供“%.*ls”的会话跟踪 ID。If the problem persists, contact customer support, and provide them the session tracing ID of '%.*ls'.

如果已建立到数据库的现有专用管理员连接 (DAC),则可能发生此错误。This error may occur if there is already an existing dedicated administrator connection (DAC) established to the database. 有关详细信息,请参阅暂时性错误For more information, see Transient errors.
4991849918 1616 无法处理请求。Cannot process request. 没有足够的资源来处理请求。Not enough resources to process request.

服务当前正忙。The service is currently busy. 请稍后重试请求。Please retry the request later. 有关详细信息,请参阅:For more information, see:
•  逻辑 SQL Server 资源限制•  Logical SQL server resource limits
•  单一数据库的基于 DTU 的限制•  DTU-based limits for single databases
•  弹性池的基于 DTU 的限制•  DTU-based limits for elastic pools
•  单一数据库的基于 vCore 的限制•  vCore-based limits for single databases
•  弹性池的基于 vCore 的限制•  vCore-based limits for elastic pools
•  Azure SQL 托管实例资源限制•  Azure SQL Managed Instance resource limits.
4991949919 1616 无法处理创建或更新请求。Cannot process create or update request. 订阅“%ld”有太多创建或更新操作正在进行。Too many create or update operations in progress for subscription "%ld".

服务正忙于为订阅或服务器处理多个创建或更新请求。The service is busy processing multiple create or update requests for your subscription or server. 为了优化资源,当前阻止了请求。Requests are currently blocked for resource optimization. 请查询 sys.dm_operation_status 以了解挂起的操作。Query sys.dm_operation_status for pending operations. 请等到挂起的创建或更新请求完成后,或删除其中一个挂起的请求,再重试请求。Wait until pending create or update requests are complete or delete one of your pending requests and retry your request later. 有关详细信息,请参阅:For more information, see:
•  逻辑 SQL Server 资源限制•  Logical SQL server resource limits
•  单一数据库的基于 DTU 的限制•  DTU-based limits for single databases
•  弹性池的基于 DTU 的限制•  DTU-based limits for elastic pools
•  单一数据库的基于 vCore 的限制•  vCore-based limits for single databases
•  弹性池的基于 vCore 的限制•  vCore-based limits for elastic pools
•  Azure SQL 托管实例资源限制•  Azure SQL Managed Instance resource limits.
4992049920 1616 无法处理请求。Cannot process request. 订阅“%ld”有太多操作正在进行。Too many operations in progress for subscription "%ld".

服务正忙于为此订阅处理多个请求。The service is busy processing multiple requests for this subscription. 为了优化资源,当前阻止了请求。Requests are currently blocked for resource optimization. 请查询 sys.dm_operation_status 以了解操作状态。Query sys.dm_operation_status for operation status. 请等到挂起的请求完成,或删除其中一个挂起的请求,然后重试请求。Wait until pending requests are complete or delete one of your pending requests and retry your request later. 有关详细信息,请参阅:For more information, see:
•  逻辑 SQL Server 资源限制•  Logical SQL server resource limits
•  单一数据库的基于 DTU 的限制•  DTU-based limits for single databases
•  弹性池的基于 DTU 的限制•  DTU-based limits for elastic pools
•  单一数据库的基于 vCore 的限制•  vCore-based limits for single databases
•  弹性池的基于 vCore 的限制•  vCore-based limits for elastic pools
•  Azure SQL 托管实例资源限制•  Azure SQL Managed Instance resource limits.
42214221 1616 由于等待“HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING”的时间过长,登录以读取次要副本失败。Login to read-secondary failed due to long wait on 'HADR_DATABASE_WAIT_FOR_TRANSITION_TO_VERSIONING'. 副本不可用于登录,因为回收副本时缺少正在进行中的事务的行版本。The replica is not available for login because row versions are missing for transactions that were in-flight when the replica was recycled. 可以通过回滚或提交主要副本上的活动事务来解决此问题。The issue can be resolved by rolling back or committing the active transactions on the primary replica. 通过避免在主要副本上长时间写入事务,可以将此状况的发生次数降到最低。Occurrences of this condition can be minimized by avoiding long write transactions on the primary.

解决暂时性连接问题的步骤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.
  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.

实现重试逻辑Implementing Retry Logic

强烈建议客户端程序包含重试逻辑,以便它可以提供一段时间来让暂时性故障纠正自身,并尝试重建连接。It is strongly recommended that your client program has retry logic so that it could reestablish a connection after giving the transient fault time to correct itself. 我们建议在第一次重试前延迟 5 秒钟。We recommend that you delay for 5 seconds before your first retry. 如果在少于 5 秒的延迟后重试,云服务有超载的风险。Retrying after a delay shorter than 5 seconds risks overwhelming the cloud service. 对于后续的每次重试,延迟应以指数级增大,最大值为 60 秒。For each subsequent retry the delay should grow exponentially, up to a maximum of 60 seconds.

有关重试逻辑的代码示例,请参阅:For code examples of retry logic, see:

有关在应用程序中处理暂时性错误的其他信息,请查看排查 SQL 数据库的暂时性连接错误For additional information on handling transient errors in your application review Troubleshooting transient connection errors to SQL Database

连接池 (ADO.NET) 中提供了有关使用 ADO.NET 的客户端的阻塞期的说明。A discussion of the blocking period for clients that use ADO.NET is available in Connection Pooling (ADO.NET).

如果应用程序无法连接到服务器,则会出现此问题。The issue occurs if the application can't connect to the server.

若要解决此问题,请尝试执行解决常见连接问题的步骤部分所述的步骤(按所述顺序执行)。To resolve this issue, try the steps (in the order presented) in the Steps to fix common connection issues section.

找不到或无法访问服务器/实例(错误 26、40、10053)The server/instance was not found or was not accessible (errors 26, 40, 10053)

错误 26:查找指定的服务器时出错Error 26: Error Locating server specified

System.Data.SqlClient.SqlException: 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: 26 – Error Locating Server/Instance Specified)

错误 40:无法与服务器建立连接Error 40: Could not open a connection to the server

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)

错误 10053:在接收来自服务器的结果时发生传输级错误Error 10053: A transport-level error has occurred when receiving results from the server

10053: A transport-level error has occurred when receiving results from the server. (Provider: TCP Provider, error: 0 - An established connection was aborted by the software in your host machine)

如果应用程序无法连接到服务器,则会出现这些问题。These issues occur if the application can't connect to the server.

若要解决这些问题,请尝试执行解决常见连接问题的步骤部分所述的步骤(按所述顺序执行)。To resolve these issues, try the steps (in the order presented) in the Steps to fix common connection issues section.

由于防火墙问题而无法连接到服务器Cannot connect to server due to firewall issues

错误 40615:无法连接到 <服务器名称>Error 40615: Cannot connect to < servername >

若要解决此问题,请通过 Azure 门户在 SQL 数据库上配置防火墙设置To resolve this issue, configure firewall settings on SQL Database through the Azure portal.

错误 5:无法连接到 <服务器名称>Error 5: Cannot connect to < servername >

若要解决此问题,请在客户端与 Internet 之间的所有防火墙上,确保为出站连接打开端口 1433。To resolve this issue, make sure that port 1433 is open for outbound connections on all firewalls between the client and the internet.

无法登录到服务器(错误 18456、40531)Unable to log in to the server (errors 18456, 40531)

用户 '< 用户名>' 登录失败Login failed for user '< User name >'

Login failed for user '<User name>'.This session has been assigned a tracing ID of '<Tracing ID>'. Provide this tracing ID to customer support when you need assistance. (Microsoft SQL Server, Error: 18456)

若要解决此问题,请让服务管理员为你提供有效的用户名和密码。To resolve this issue, contact your service administrator to provide you with a valid user name and password.

服务管理员通常可使用以下步骤添加登录凭据:Typically, the service administrator can use the following steps to add the login credentials:

  1. 使用 SQL Server Management Studio (SSMS) 登录到服务器。Log in to the server by using SQL Server Management Studio (SSMS).

  2. 运行以下 SQL 查询,以检查是否已禁用登录名:Run the following SQL query to check whether the login name is disabled:

    SELECT name, is_disabled FROM sys.sql_logins
    
  3. 如果禁用了相应的名称,请使用以下语句来启用它:If the corresponding name is disabled, enable it by using the following statement:

    Alter login <User name> enable
    
  4. 如果该 SQL 登录用户名不存在,请执行以下步骤创建该用户名:If the SQL login user name doesn't exist, create it by following these steps:

    1. 在 SSMS 中,双击“安全性”将其展开。In SSMS, double-click Security to expand it.
    2. 右键单击“登录”,然后选择“新建登录名”。Right-click Logins, and then select New login.
    3. 在生成的带占位符的脚本中,编辑并运行以下 SQL 查询:In the generated script with placeholders, edit and run the following SQL query:
    CREATE LOGIN <SQL_login_name, sysname, login_name>
    WITH PASSWORD = '<password, sysname, Change_Password>'
    GO
    
  5. 双击“数据库”。Double-click Database.

  6. 选择要授予用户权限的数据库。Select the database that you want to grant the user permission to.

  7. 双击“安全性”。Double-click Security.

  8. 右键单击“用户”,然后选择“新建用户”。Right-click Users, and then select New User.

  9. 在生成的带占位符的脚本中,编辑并运行以下 SQL 查询:In the generated script with placeholders, edit and run the following SQL query:

    CREATE USER <user_name, sysname, user_name>
    FOR LOGIN <login_name, sysname, login_name>
    WITH DEFAULT_SCHEMA = <default_schema, sysname, dbo>
    GO
    -- Add user to the database owner role
    
    EXEC sp_addrolemember N’db_owner’, N’<user_name, sysname, user_name>’
    GO
    

    备注

    也可使用 sp_addrolemember 将特定的用户映射到特定的数据库角色。You can also use sp_addrolemember to map specific users to specific database roles.

有关详细信息,请参阅在 Azure SQL 数据库中管理数据库和登录名For more information, see Managing databases and logins in Azure SQL Database.

连接超时过期错误Connection timeout expired errors

System.Data.SqlClient.SqlException (0x80131904):连接超时过期System.Data.SqlClient.SqlException (0x80131904): Connection Timeout Expired

System.Data.SqlClient.SqlException (0x80131904): Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=3; handshake=29995;

System.Data.SqlClient.SqlException (0x80131904):超时过期System.Data.SqlClient.SqlException (0x80131904): Timeout expired

System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

System.Data.Entity.Core.EntityException:基础提供程序在打开时失败System.Data.Entity.Core.EntityException: The underlying provider failed on Open

System.Data.Entity.Core.EntityException: The underlying provider failed on Open. -> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. -> System.ComponentModel.Win32Exception: The wait operation timed out

无法连接到 <服务器名称>Cannot connect to < server name >

Cannot connect to <server name>.ADDITIONAL INFORMATION:Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=231; handshake=983; [Login] initialization=0; authentication=0; [Post-Login] complete=13000; (Microsoft SQL Server, Error: -2) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=-2&LinkId=20476 The wait operation timed out

这些异常可能是连接或查询问题造成的。These exceptions can occur either because of connection or query issues. 若要确认此错误是否由连接问题造成,请参阅确认错误是否由连接问题造成To confirm that this error is caused by connectivity issues, see Confirm whether an error is caused by a connectivity issue.

发生连接超时的原因是应用程序无法连接到服务器。Connection timeouts occur because the application can't connect to the server. 若要解决此问题,请尝试执行解决常见连接问题的步骤部分所述的步骤(按所述顺序执行)。To resolve this issue, try the steps (in the order presented) in the Steps to fix common connection issues section.

弹性池错误Elastic pool errors

以下错误与创建和使用弹性池有关:The following errors are related to creating and using elastic pools:

错误代码Error code 严重性Severity 说明Description 纠正措施Corrective action
11321132 1717 弹性池已达到其存储限制。The elastic pool has reached its storage limit. 弹性池的存储使用不能超过 (%d) MB。The storage usage for the elastic pool cannot exceed (%d) MBs. 到达弹性池的存储限制时,尝试向数据库写入数据。Attempting to write data to a database when the storage limit of the elastic pool has been reached. 有关资源限制的信息,请参阅:For information on resource limits, see:
•  弹性池的基于 DTU 的限制•  DTU-based limits for elastic pools
•  弹性池的基于 vCore 的限制•  vCore-based limits for elastic pools.
在可能的情况下,考虑增加弹性池的 DTU 数并/或将存储添加到弹性池,以便提高其存储限制、减少弹性池中各数据库使用的存储,或者从弹性池中删除数据库。Consider increasing the DTUs of and/or adding storage to the elastic pool if possible in order to increase its storage limit, reduce the storage used by individual databases within the elastic pool, or remove databases from the elastic pool. 有关弹性池缩放的信息,请参阅缩放弹性池资源For elastic pool scaling, see Scale elastic pool resources.
1092910929 1616 %s 最小保证为 %d,最大限制为 %d,数据库的当前使用率为 %d。The %s minimum guarantee is %d, maximum limit is %d, and the current usage for the database is %d. 但是,服务器当前太忙,无法支持针对该数据库的数目大于 %d 的请求。However, the server is currently too busy to support requests greater than %d for this database. 有关资源限制的信息,请参阅:For information on resource limits, see:
•  弹性池的基于 DTU 的限制•  DTU-based limits for elastic pools
•  弹性池的基于 vCore 的限制•  vCore-based limits for elastic pools.
否则,请稍后再试。Otherwise, please try again later. 每个数据库的 DTU/vCore 最小值;每个数据库的 DTU/vCore 最大值。DTU / vCore min per database; DTU / vCore max per database. 弹性池中所有数据库上尝试的并发辅助进程(请求)总数超过池限制。The total number of concurrent workers (requests) across all databases in the elastic pool attempted to exceed the pool limit.
在可能的情况下,考虑增加弹性池的 DTU 数或 vCores 数,以便提高其辅助角色限制,或者从弹性池中删除数据库。Consider increasing the DTUs or vCores of the elastic pool if possible in order to increase its worker limit, or remove databases from the elastic pool.
4084440844 1616 弹性池中数据库“%ls”(位于服务器“%ls”上)是“%ls”版本的数据库,不能有连续的复制关系。Database '%ls' on Server '%ls' is a '%ls' edition database in an elastic pool and cannot have a continuous copy relationship. 空值N/A
4085740857 1616 找不到服务器“%ls”的弹性池,弹性池名称:“%ls”。Elastic pool not found for server: '%ls', elastic pool name: '%ls'. 指定的弹性池在指定的服务器中不存在。Specified elastic pool does not exist in the specified server. 提供有效的弹性池名称。Provide a valid elastic pool name.
4085840858 1616 弹性池“%ls”已存在于服务器“%ls”中。Elastic pool '%ls' already exists in server: '%ls'. 指定的弹性池已存在于指定的服务器中。Specified elastic pool already exists in the specified server. 提供新弹性池名称。Provide new elastic pool name.
4085940859 1616 弹性池不支持服务层级“%ls”。Elastic pool does not support service tier '%ls'. 进行弹性池预配时,不支持指定服务层级。Specified service tier is not supported for elastic pool provisioning. 提供正确的版本,或者将服务层级留空以使用默认服务层级。Provide the correct edition or leave service tier blank to use the default service tier.
4086040860 1616 弹性池“%ls”和服务目标“%ls”的组合无效。Elastic pool '%ls' and service objective '%ls' combination is invalid. 仅当资源类型指定为“ElasticPool”时,才能一起指定弹性池和服务层级。Elastic pool and service tier can be specified together only if resource type is specified as 'ElasticPool'. 指定正确的弹性池和服务层级组合。Specify correct combination of elastic pool and service tier.
4086140861 1616 数据库版本“%.ls”必须与弹性池服务层级“%. ls”相同。The database edition '%.ls' cannot be different than the elastic pool service tier which is '%. ls'. 数据库版本不同于弹性池服务层级。The database edition is different than the elastic pool service tier. 请勿指定不同于弹性池服务层级的数据库版本。Do not specify a database edition which is different than the elastic pool service tier. 请注意,数据库版本不需要指定。Note that the database edition does not need to be specified.
4086240862 1616 如果指定了弹性池服务目标,则必须指定弹性池名称。Elastic pool name must be specified if the elastic pool service objective is specified. 弹性池服务目标没有唯一地标识弹性池。Elastic pool service objective does not uniquely identify an elastic pool. 如果使用弹性池服务目标,则指定弹性池名称。Specify the elastic pool name if using the elastic pool service objective.
4086440864 1616 对于服务层级“%.*ls”来说,弹性池的 DTU 数必须至少为 (%d) 个 DTU。The DTUs for the elastic pool must be at least (%d) DTUs for service tier '%.*ls'. 尝试将弹性池的 DTU 数设置为最小限制以下。Attempting to set the DTUs for the elastic pool below the minimum limit. 重新尝试将弹性池的 DTU 数至少设置为最小限制。Retry setting the DTUs for the elastic pool to at least the minimum limit.
4086540865 1616 对于服务层级“%.*ls”来说,弹性池的 DTU 数不能超过 (%d) 个 DTU。The DTUs for the elastic pool cannot exceed (%d) DTUs for service tier '%.*ls'. 尝试将弹性池的 DTU 数设置为高出最大限制。Attempting to set the DTUs for the elastic pool above the maximum limit. 重新尝试将弹性池的 DTU 数设置为不超过最大限制。Retry setting the DTUs for the elastic pool to no greater than the maximum limit.
4086740867 1616 对于服务层级“%.*ls”来说,每个数据库的 DTU 最大值必须至少为 (%d)。The DTU max per database must be at least (%d) for service tier '%.*ls'. 尝试将每个数据库的 DTU 最大值设置为低于支持的限制。Attempting to set the DTU max per database below the supported limit. 考虑使用支持所需设置的弹性池服务层级。Consider using the elastic pool service tier that supports the desired setting.
4086840868 1616 对于服务层级“%.*ls”来说,每个数据库的 DTU 最大值不能超过 (%d)。The DTU max per database cannot exceed (%d) for service tier '%.*ls'. 尝试将每个数据库的 DTU 最大值设置为超出支持的限制。Attempting to set the DTU max per database beyond the supported limit. 考虑使用支持所需设置的弹性池服务层级。Consider using the elastic pool service tier that supports the desired setting.
4087040870 1616 对于服务层级“%.*ls”来说,每个数据库的 DTU 最小值不能超过 (%d)。The DTU min per database cannot exceed (%d) for service tier '%.*ls'. 尝试将每个数据库的 DTU 最小值设置为超出支持的限制。Attempting to set the DTU min per database beyond the supported limit. 考虑使用支持所需设置的弹性池服务层级。Consider using the elastic pool service tier that supports the desired setting.
4087340873 1616 数据库数目 (%d) 和每个数据库的 DTU 最小值 (%d) 不能超过弹性池的 DTU 数 (%d)。The number of databases (%d) and DTU min per database (%d) cannot exceed the DTUs of the elastic pool (%d). 尝试指定弹性池中数据库的 DTU 最小值,该最小值超出弹性池的 DTU 数。Attempting to specify DTU min for databases in the elastic pool that exceeds the DTUs of the elastic pool. 考虑增加弹性池的 DTU 数,或者降低每个数据库的 DTU 最小值,或者降低弹性池中数据库的数目。Consider increasing the DTUs of the elastic pool, or decrease the DTU min per database, or decrease the number of databases in the elastic pool.
4087740877 1616 除非弹性池不含任何数据库,否则不能将其删除。An elastic pool cannot be deleted unless it does not contain any databases. 弹性池包含一个或多个数据库,因此无法将其删除。The elastic pool contains one or more databases and therefore cannot be deleted. 删除弹性池中的数据库,以便删除弹性池。Remove databases from the elastic pool in order to delete it.
4088140881 1616 弹性池“%.*ls”已达到其数据库计数限制。The elastic pool '%.*ls' has reached its database count limit. 对于 DTU 数为 (%d) 的弹性池,弹性池的数据库计数限制不能超出 (%d)。The database count limit for the elastic pool cannot exceed (%d) for an elastic pool with (%d) DTUs. 达到弹性池的数据库计数限制时,尝试创建数据库或将其添加到弹性池。Attempting to create or add database to elastic pool when the database count limit of the elastic pool has been reached. 在可能的情况下,考虑增加弹性池的 DTU 数,以便提高其数据库限制,或者从弹性池中删除数据库。Consider increasing the DTUs of the elastic pool if possible in order to increase its database limit, or remove databases from the elastic pool.
4088940889 1616 弹性池“%.*ls”的 DTU 数或存储限制不能降低,因为这样就无法为其数据库提供足够的存储空间。The DTUs or storage limit for the elastic pool '%.*ls' cannot be decreased since that would not provide sufficient storage space for its databases. 尝试将弹性池的存储限制降低到其存储使用量以下。Attempting to decrease the storage limit of the elastic pool below its storage usage. 考虑降低弹性池中各个数据库的存储使用量,或者从池中删除数据库以降低其 DTU 数或存储限制。Consider reducing the storage usage of individual databases in the elastic pool or remove databases from the pool in order to reduce its DTUs or storage limit.
4089140891 1616 每个数据库的 DTU 最小值 (%d) 不能超过每个数据库的 DTU 最大值 (%d)。The DTU min per database (%d) cannot exceed the DTU max per database (%d). 尝试将每个数据库的 DTU 最小值设置为高于每个数据库的 DTU 最大值。Attempting to set the DTU min per database higher than the DTU max per database. 确保每个数据库的 DTU 最小值不超过每个数据库的 DTU 最大值。Ensure the DTU min per databases does not exceed the DTU max per database.
TBDTBD 1616 弹性池中单个数据库的存储大小不能超过“%.*ls”服务层级弹性池所允许的最大大小。The storage size for an individual database in an elastic pool cannot exceed the max size allowed by '%.*ls' service tier elastic pool. 数据库的最大大小超过弹性池服务层级允许的最大大小。The max size for the database exceeds the max size allowed by the elastic pool service tier. 将数据库的最大大小设置为处于弹性池服务层级允许的最大大小限制范围内。Set the max size of the database within the limits of the max size allowed by the elastic pool service tier.

无法打开登录名请求的数据库 "master"。Cannot open database "master" requested by the login. 登录失败The login failed

之所以出现此问题,是因为该帐户无权访问 master 数据库。This issue occurs because the account doesn't have permission to access the master database. 但默认情况下,SQL Server Management Studio (SSMS) 会尝试连接到 master 数据库。But by default, SQL Server Management Studio (SSMS) tries to connect to the master database.

若要解决此问题,请执行以下步骤:To resolve this issue, follow these steps:

  1. 在 SSMS 的登录屏幕上选择“选项”,然后选择“连接属性”。 On the login screen of SSMS, select Options, and then select Connection Properties.

  2. 在“连接到数据库”字段中,输入用户的默认数据库名称作为默认登录数据库,然后选择“连接”。 In the Connect to database field, enter the user’s default database name as the default login database, and then select Connect.

    连接属性

确认错误是否由连接问题造成Confirm whether an error is caused by a connectivity issue

若要确认某个错误是否由连接问题造成,请查看帧的堆栈跟踪,其中会显示打开连接的调用,如下所示(请注意对 SqlConnection 类的引用):To confirm whether an error is caused by a connectivity issue, review the stack trace for frames that show calls to open a connection like the following ones (note the reference to the SqlConnection class):

System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
 at System.Data.SqlClient.SqlConnection.Open()
 at AzureConnectionTest.Program.Main(String[] args)
ClientConnectionId:<Client connection ID>

如果异常是由查询问题触发的,则你会看到如下所示的调用堆栈(请注意对 SqlCommand 类的引用)。When the exception is triggered by query issues, you'll notice a call stack that's similar to the following (note the reference to the SqlCommand class). 对于这种情况,请优化查询In this situation, tune your queries.

  at System.Data.SqlClient.SqlCommand.ExecuteReader()
  at AzureConnectionTest.Program.Main(String[] args)
  ClientConnectionId:<Client ID>

有关优化性能的更多指导,请参阅以下资源:For additional guidance on fine-tuning performance, see the following resources:

解决常见连接问题的步骤Steps to fix common connection issues

  1. 确保已在应用程序服务器上启用 TCP/IP 作为客户端协议。Make sure that TCP/IP is enabled as a client protocol on the application server. 有关详细信息,请参阅配置客户端协议For more information, see Configure client protocols. 在未安装 SQL 工具的应用程序服务器上,运行 cliconfg.exe(SQL Server 客户端网络实用工具)来验证是否已启用 TCP/IP。On application servers where you don't have SQL tools installed, verify that TCP/IP is enabled by running cliconfg.exe (SQL Server Client Network utility).

  2. 检查应用程序的连接字符串,确保配置正确。Check the application’s connection string to make sure it's configured correctly. 例如,确保连接字符串指定了正确的端口 (1433) 和完全限定的服务器名称。For example, make sure that the connection string specifies the correct port (1433) and fully qualified server name. 请参阅获取连接信息See Get connection information.

  3. 尝试增大连接超时值。Try increasing the connection timeout value. 我们建议至少使用 30 秒连接超时。We recommend using a connection timeout of at least 30 seconds.

  4. 使用 SQL Server Management Studio (SSMS)、UDL 文件、ping 或 telnet 来测试应用程序服务器与 Azure SQL 数据库之间的连接。Test the connectivity between the application server and the Azure SQL Database by using SQL Server management Studio (SSMS), a UDL file, ping, or telnet. 有关详细信息,请参阅排查连接问题连接问题的诊断For more information, see Troubleshooting connectivity issues and Diagnostics for connectivity issues.

    备注

    作为故障排除步骤,还可以在不同的客户端计算机上测试连接。As a troubleshooting step, you can also test connectivity on a different client computer.

  5. 最佳做法是确保实施重试逻辑。As a best practice, make sure that the retry logic is in place. 有关重试逻辑的详细信息,请参阅排查 SQL 数据库的暂时性故障和连接错误For more information about retry logic, see Troubleshoot transient faults and connection errors to SQL Database.

如果这些步骤无法解决问题,请尝试收集更多的数据,然后联系支持人员。If these steps don't resolve your problem, try to collect more data and then contact support. 如果应用程序是云服务,请启用日志记录。If your application is a cloud service, enable logging. 此步骤会返回发生失败时的 UTC 时间戳。This step returns a UTC time stamp of the failure. 此外,SQL 数据库会返回跟踪 ID。Additionally, SQL Database returns the tracing ID. Azure 客户支持服务可使用此信息。Azure Customer Support Services can use this information.

有关如何启用日志记录的详细信息,请参阅为 Azure 应用服务中的应用启用诊断日志记录For more information about how to enable logging, see Enable diagnostics logging for apps in Azure App Service.

后续步骤Next steps