简体   繁体   中英

Windows service: check if base service is running

I have created a window service which connects to SQL server.

But the problem is when Server restarts, my service try to connect to SQL server before SQL server service starts and due to which my service throws exception.

Is there any way to detect if base service(SQL server) is running before my service starts.

I have seen here but this is for installation time only.

You can define SQL Server to be a dependency of your service, but that does not solve the problem. The SQL Server service reports to be in "running" status very quickly. However when trying to connect you will get an exception, because it is still busy internally.

There seems to be no reliable way other than just retrying to connect to the database until it finally succeeds.

See also this question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM