Starting a service error.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rottmanj
    New Member
    • Jan 2008
    • 46

    Starting a service error.

    I have written an application that installs a service and then is supposed to start the service. Everything works great except for the service starting(either with AfterIntall or starting it from the window service manager).

    The error I get is
    Code:
    System.InvalidOperationException: Cannot start service qbLinxService on computer ',', ------> System.ComponentModel.Win32Exception: The service did not respond to the start or control request in a timely fashion
    Now everything I have read thus far states that this is an error only with .net framework 1.1. I am currently running 3.5 on my testing machine. So I am a bit confused as to what is going on.

    Here is my service code. Any help with this is greatly appreciated.
    Code:
    namespace qbLinx
    {
        partial class qbLinxService : ServiceBase
        {
            public qbLinxService()
            {
                InitializeComponent();
            }
    
            protected override void OnStart(string[] args)
            {
                //qbConnect qbCnn = new qbConnect();
                //qbCnn.qbTimer();
            }
    
            protected override void OnStop()
            {
                // TODO: Add code here to perform any tear-down necessary to stop your service.
            }
        }
    }
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    If after installation of service (installutil service name ) if you cant start the service from service manager ... i guess the fault may lie in your code... You are tryin to connect to database on start of service?
    Code:
    qbConnect qbCnn = new qbConnect();
    if yes then maybe it timeouts? you need to take care of exception conditions for windows service..
    any code taking more than 60 sec is not recommended for windows service (correct me here if i am wrong )... how abt using asynchronous delegates? Can you post the error message and error code?
    Assuming you are tryin to connect to DB ...how can you be sure that DB server is running? and if the DB is on the same machine... your service will have dependency on other service ..
    try this
    Code:
    protected override void OnStart(string[] args)
           {
    try{
                //qbConnect qbCnn = new qbConnect();
               //qbCnn.qbTimer();
    }
    
    catch(Exception e)
    {
    string error_file = System.Environment.ExpandEnvironmentVariables("%SystemDrive%").ToString() + @"\Error.txt";
    
                using (FileStream fs = new FileStream(error_file, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.BaseStream.Seek(0, SeekOrigin.End);
                        sw.WriteLine(e.Message.Tostring());
    
    
                    }
                }
    
    }
            }
    Also i would recommend using good usage of threads in a windows service .. so that it does not block... remember start has to return back as soon as possible...

    Comment

    • rottmanj
      New Member
      • Jan 2008
      • 46

      #3
      In the code I posted, I commeted out all actions that should take place with the onstart method. This is what is confusing me, the onstart method is empty of all action and it still fails to start.

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Originally posted by rottmanj
        In the code I posted, I commeted out all actions that should take place with the onstart method. This is what is confusing me, the onstart method is empty of all action and it still fails to start.
        well in that case the problem lies elsewhere .... try reinstalling the windows service.. which i m sure you did.... try on another computer, if it works ...then maybe reload OS?

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          The error message might be a "best guess" by windows on how to respond.
          If your OnStart() does nothing (including not starting any threads) and returns right away, you normally get the message "service started then stopped, this could be do to (blah blah blah)" But maybe if you don't actually call the STOP function, it thinks there is an error starting the service?

          Comment

          Working...