Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting Windows service automatically at Windows startup that is dependent on Oracle

I have developed a Windows Service, that must start automatically during Windows startup. This service connects to an Oracle db, so I made my service dependent on Oracle Services by sc command line utility: sc config MyService depend= OracleServiceXE/OracleXETNSListener

So far so good, dependency was set succesfully. But when Windows starting, my service could not start, I get the following (Oracle) error message: "ORA-12528: TNS:listener: all appropriate instances are blocking new connections".

As I think, the Oracle services are started when my service starts, but they are not 'fully initialized'. After some seconds I can start my service from service consol without any problem.

So, how can I start automatically my service at Windows Startup which is dependent on an Oracle DB connection?

My service was developed in C# on .Net 4 platform, in VS 2010 environment.

Pls. help me, it is a really important task form me!

like image 797
Tom Avatar asked May 28 '11 12:05

Tom


1 Answers

Remember, the code for your service's startup should do as little as possible. In other words, don't have your service startup check for availability of the Oracle server, or indeed do anything. Have your service do the following:

  • Log the fact that it's started
  • Load any applicable configuration from config files/registry/etc
  • Spin-up a thread that will try and "startup" the service properly every N seconds, and will repeat M times until it gives up. Have N and M configurable from your config file/registry

Have the thread "try" to connect to the applicable Oracle server and if it fails, go to sleep for N seconds, and do this M times. If it succeeds it can then start doing the "meat" of what it's supposed to.

Ironically, it's probably the fact that the Oracle service does something similar to what I've proposed you do that's causing you the problem. By returning "Yes, I've started" quickly back to Windows when it's started, it allows your service to then be loaded, even though Oracle is still busy spinning stuff up. Ideally in this scenario rather than rejecting your requests, Oracle should enqueue them for processing when it is ready.

like image 60
Rob Avatar answered Nov 03 '22 02:11

Rob