問題描述
服務(wù)依賴不足以保證數(shù)據(jù)庫客戶端在系統(tǒng)重啟后會(huì)發(fā)現(xiàn)他們的 SQL Server 啟動(dòng)并運(yùn)行.他們可能能夠創(chuàng)建到 master 數(shù)據(jù)庫的連接,但特定的數(shù)據(jù)庫可能仍在打開過程中(在恢復(fù)模式下),并且在最初的一段時(shí)間內(nèi)將拒絕連接.
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.
延遲的確切持續(xù)時(shí)間變化很大,取決于系統(tǒng)上的數(shù)據(jù)庫數(shù)量、恢復(fù)模式、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.
處理對(duì)客戶端的依賴的眾所周知的方法是休眠和重試.然而,這種方法似乎并不完全干凈或可靠,尤其是當(dāng)客戶在技術(shù)和所有權(quán)方面存在差異并且這種競爭條件很少出現(xiàn)時(shí).
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.
是否有更好的方法來同步客戶端與服務(wù)器啟動(dòng),最好是通過將 SQL Server 服務(wù)保持在正在啟動(dòng)"狀態(tài)直到所有數(shù)據(jù)庫都被打開或標(biāo)記為可疑?
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?
推薦答案
創(chuàng)建一個(gè) Windows 服務(wù),該服務(wù)嘗試訪問數(shù)據(jù)庫,除非成功建立可靠的連接,否則該服務(wù)不會(huì)報(bào)告自己已啟動(dòng).基本上該服務(wù)會(huì)返回一個(gè)錯(cuò)誤,服務(wù)管理器會(huì)嘗試根據(jù)服務(wù)設(shè)置運(yùn)行它.
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.
現(xiàn)在,您可以依賴其他服務(wù)中的新服務(wù)來保證數(shù)據(jù)庫響應(yīng).
And now you can depend on that new service in your other services that would guarantee that the database is responsive.
相關(guān)問題
- 在 C# 中,確定數(shù)據(jù)庫是否已啟動(dòng)并正在運(yùn)行的最佳方法是什么?
更新
此外,要了解數(shù)據(jù)庫是否已啟動(dòng)并正在運(yùn)行,更簡潔的方法是檢查以下值:
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"之外什么都不說,那么數(shù)據(jù)庫還沒有準(zhǔn)備好.(如果它存在的話)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
這篇關(guān)于數(shù)據(jù)庫客戶端:如何在 SQL Server 重啟后等待數(shù)據(jù)庫激活?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!