2016-08-22 17 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分鐘的新連接,直到目前的會議和工作人員完成或者被殺死。