|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Windows ServiceI'm writing a windows service that depends on sql server running. I
could add dependency on sql server in service setup, but it can be running on different machine. Can I block in OnStart till sql server is operational? -- Semper Fidelis Adam Klobukowski at***@gabo.pl I would not recommend it .. I would instead start a thread from onstart that
then blocked until SQLServer was up and running .. maybe logging an error every few minutes saying it could not get to the SQL Server. Cheers, Greg Young MVP - C# http://geekswithblogs.net/gyoung Show quote "Adam Klobukowski" <at***@gabo.pl> wrote in message news:e5m617$gtb$1@atlantis.news.tpi.pl... > I'm writing a windows service that depends on sql server running. I could > add dependency on sql server in service setup, but it can be running on > different machine. Can I block in OnStart till sql server is operational? > > -- > Semper Fidelis > > Adam Klobukowski > at***@gabo.pl I just did this two days ago. Blocking OnStart causes the MMC to not report
your service's status accurately, which might cause your users to do things out of frustration like continually restarting the service or stopping it while you're still trying to make a connection. What I did was use the ThreadPool to QueueUserWorkItem that made my Sql connection. That way I could avoid blocking the OnStart method. I wouldn't suggest adding some sort of polling to retry the connection if it fails. Generally, when a sql connex fails, its because the thing isn't configged correctly. Polling is also a no-no in a service. Instead, I dropped a message in the Event Log (EventLog.WriteEntry) with a description of the problem and halted the service. Show quote "Adam Klobukowski" wrote: > I'm writing a windows service that depends on sql server running. I > could add dependency on sql server in service setup, but it can be > running on different machine. Can I block in OnStart till sql server is > operational? > > -- > Semper Fidelis > > Adam Klobukowski > at***@gabo.pl > |
|||||||||||||||||||||||