gpt4 book ai didi

c# - Azure sql 数据库相关异常

转载 作者:行者123 更新时间:2023-12-02 06:49:22 25 4
gpt4 key购买 nike

我在 azure 中有一个数据库,它有标准 s2 版本。在我的应用程序日志中,我总是看到许多这样的格式的异常:

1.

System.Data.SqlClient.SqlException: The client was unable to establish a connection because of an error during connection initialization process before login. Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) ---> System.ComponentModel.Win32Exception: An existing connection was forcibly closed by the remote host

2.

System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached

3

System.Data.SqlClient.SqlException (0x80131904): The client was unable to establish a connection because of an error during connection initialization process before login. Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) ---> System.ComponentModel.Win32Exception (0x80004005): An existing connection was forcibly closed by the remote host.

我使用 SqlAzureExecutionStrategy,因此在重试一定次数后会引发此异常。

我在 azure portla 上看到了不同的性能指标,但看起来它们都还不错。

如何识别问题?

最佳答案

我认为您的数据库负载过重,或者您有一些查询仍在运行或未释放连接。

我使用此查询来查看正在运行的内容:

SELECT (SELECT TOP 1 SUBSTRING(s2.text,statement_start_offset / 2+1 , 
( (CASE WHEN statement_end_offset = -1
THEN (LEN(CONVERT(nvarchar(max),s2.text)) * 2)
ELSE statement_end_offset END) - statement_start_offset) / 2+1)) AS sql_statement,
s1.* FROM sys.dm_exec_requests s1
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS s2
ORDER BY 1

查看此处是否仍有查询正在运行,或者密切关注 Azure 门户中的 CPU 使用情况。

S2 数据库不是特别好,它会限制您的请求,因此如果您执行大量请求(即使是小请求),它可能会拒绝它们。

您的重试策略也可能使问题变得更糟,但在它已被填满时向其抛出更多请求。如果是这种情况,您可以尝试使用指数退避。

关于c# - Azure sql 数据库相关异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39081172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com