2016-08-22 74 views
1

我在蔚蓝的数据库已经非标准S2 edition.In我的应用程序的日志,我总是看到许多例外这样的格式:Azure的SQL数据库相关的异常

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

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上看到不同的性能指标,但看起来他们没问题。

如何识别问题?

+1

'我如何识别问题?'用Azure SQL DB打开支持案例。 –

+0

您的AzureSQL数据库与您的应用程序代码位于相同的Azure区域中吗?您是否直接通过Internet连接到Azure SQL数据库(例如,从桌面客户端软件?)。 – Dai

+0

还在azure查看你的活动日志表了解更多详情 – TheGameiswar

回答

1

我认为你的数据库负载太重,或者你有一些查询仍在运行或者不能放开连接。

我用这个查询查看正在运行什么:

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数据库不是特别好,它会抑制你的请求,所以如果你正在做很多(甚至是小的)请求,它可能会拒绝它们。

您的重试策略也可能导致问题变得更糟,但当它已经被填满时,会向它发出更多请求。如果是这种情况,你可以尝试使用指数后退。

0

所有这三个可以解释你的连接池设计。您是重新使用连接,还是每次调用数据库打开它自己的连接?你在每个DBContext的末尾关闭连接吗?你是否正在实现任何一种缓存层来减少到你的数据库的往返次数?

这里有一种方法来查看它是否是您的池的问题。从门户转到有问题的数据库,查看资源利用率图,然后点击编辑。

Default resource graph

然后从选择列表中添加会话率和工人的百分比,然后点击确定。

Resource graph choices

如果您的池是一个问题,你会发现,你的会话和工人比例较高,并可能在100%挂的时间。如果你达到100%,你可以被拒绝长达5分钟的新连接,直到目前的会议和工作人员完成或者被杀死。