Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.Net Windows Service - delaying auto startup

Status
Not open for further replies.

theomen

Programmer
Jun 2, 2004
158
GB
Hi,

I've written a windows service in VB.NET, which is set to automatically startup.

However, I am having a problem as it requires a connection to SQL Server at startup as it retrieves settings from a database table, but it is attempting to start before SQL Server, which is throwing an error because it can't access the database.

Is it possible to add dependencies to a service, so that it won't start without SQL Server?

An option I'm going to look into is adding a timer control to the application with an interval of say 2 minutes, when it ticks over it will carry on performing the required tasks to startup, but I'm unsure if this will work, and it might cause problems when installed on the server. I could also put in the error handling some code to say that if an error occurred whilst retrieving the settings then try again, but I'm worried this might cause an infinite loop if there is a problem with SQL Server and it doesn't start up.

Any advice would be much appreciated.
 
From
Potential Problems
There are a few potential problems when implementing a Windows service in .Net. Here are some issues to watch out for:

Dependencies - If your service is dependent on other services, you need to make sure this dependency information is set properly in the registry. Warning: improperly setting service dependency information in the registry could make a computer unbootable due to issues like circular dependencies - Service A cannot start before Service B and Service B cannot start before Service A - resulting in neither service ever starting. Be very careful here.

Using RegEdt32 (RegEdit will not work here due to it’s inability to add REG_MULTI_SZ types), go to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\[YOUR SERVICE] and create a new value with a name of DependOnService and a data type of REG_MULTI_SZ. Set the data to the name of the key of the service your Windows service depends on. For example, if your Windows service depends on MSMQ the enter MSMQ since MSMQ is the name of the key in this services branch. If your Windows service depends on multiple services, add each service on its own line. If you are creating distribution media for your Windows service, you can include a .reg file which includes this information (easing deployment efforts).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks ca8msm, didn't expect a response as quick as that.

Will try it out now.
 
If he never comes back, we'll know why.

Christiaan Baes
Belgium

"Time for a new sig." - Me
 
Excellent, it worked a treat (once my administrator had given me access to my registry).



 
Thanks ca8msm, didn't expect a response as quick as that.
No probs...doesn't take long to google...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top