問題描述
服務依賴不足以保證數據庫客戶端在系統重啟后會發現他們的 SQL Server 啟動并運行.他們可能能夠創建到 master 數據庫的連接,但特定的數據庫可能仍在打開過程中(在恢復模式下),并且在最初的一段時間內將拒絕連接.
Service dependency is not enough to guarantee that database clients will find their SQL Server up and running after a system reboot. They may be able to create a connection to the master database, but a specific database may still be in the process of opening (in the recovery mode) and connections to it will be refused for some initial period of time.
延遲的確切持續時間變化很大,取決于系統上的數據庫數量、恢復模式、LDF 文件大小或重啟前的流量等因素.
The exact duration of the delay is highly variable and depends on factors such as number of databases on the system, recovery mode, LDF file size, or traffic prior to the reboot.
處理對客戶端的依賴的眾所周知的方法是休眠和重試.然而,這種方法似乎并不完全干凈或可靠,尤其是當客戶在技術和所有權方面存在差異并且這種競爭條件很少出現時.
The well known approach to dealing with the dependency on the client is sleeping and retrying. However, this approach does not seem exactly clean or reliable, especially when the clients are diverse in terms of technology and ownership and when this race condition appears only very rarely.
是否有更好的方法來同步客戶端與服務器啟動,最好是通過將 SQL Server 服務保持在正在啟動"狀態直到所有數據庫都被打開或標記為可疑?
Is there any better way to synchronize the clients with the server start-up, ideally through keeping the SQL Server service in the "Starting" state until all databases have been either opened or marked suspect?
推薦答案
創建一個 Windows 服務,該服務嘗試訪問數據庫,除非成功建立可靠的連接,否則該服務不會報告自己已啟動.基本上該服務會返回一個錯誤,服務管理器會嘗試根據服務設置運行它.
Create a windows service that tries to access the database which does not report itself as having started unless successful in establishing a reliable connection. Basically that service would return an error and the service manager would try to run it according to the service settings.
現在,您可以依賴其他服務中的新服務來保證數據庫響應.
And now you can depend on that new service in your other services that would guarantee that the database is responsive.
相關問題
- 在 C# 中,確定數據庫是否已啟動并正在運行的最佳方法是什么?
更新
此外,要了解數據庫是否已啟動并正在運行,更簡潔的方法是檢查以下值:
Also, for a much cleaner way to know if the database is up and running is to check the following value:
SELECT state_desc
FROM sys.databases
WHERE name = 'YourDatabase'
如果除了ONLINE"之外什么都不說,那么數據庫還沒有準備好.(如果它存在的話)http://msdn.microsoft.com/en-us/library/ms190442.aspx
If it says anything but 'ONLINE', then the database is not yet ready. (if it exists at all) http://msdn.microsoft.com/en-us/library/ms190442.aspx
這篇關于數據庫客戶端:如何在 SQL Server 重啟后等待數據庫激活?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!