我正在使用sql server,有時我的數據庫出現故障以進行維護。我有錯誤處理代碼,所以用戶看不到錯誤頁面,而是看到一個友好的錯誤消息。我的問題是:數據庫關閉時,頁面加載並顯示錯誤消息花費很長時間。我認爲它有一些東西需要與超時屬性,但使用如何超時「與SQL Server建立連接時發生網絡相關或特定於實例的錯誤」錯誤
command.CommandTimeout = 5;
或
在web.config中connectionString
Connect Timeout=5;
似乎並沒有幫助改變它,它仍然需要很長的時間加載頁面(大約40秒)。有沒有辦法縮短這個時間?
獲取引發和記錄的例外是
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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
最小化哪個時間?連接嘗試失敗或連接嘗試失敗所需的時間更快? –
代碼拋出異常的時間。 – user1
當存儲的proc調用行被命中時,需要大約35-40秒纔會拋出異常。 – user1