By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

Starting a service error.

P: 46
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
Expand|Select|Wrap|Line Numbers
  1. 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
  2.  
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.
Expand|Select|Wrap|Line Numbers
  1. namespace qbLinx
  2. {
  3.     partial class qbLinxService : ServiceBase
  4.     {
  5.         public qbLinxService()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         protected override void OnStart(string[] args)
  11.         {
  12.             //qbConnect qbCnn = new qbConnect();
  13.             //qbCnn.qbTimer();
  14.         }
  15.  
  16.         protected override void OnStop()
  17.         {
  18.             // TODO: Add code here to perform any tear-down necessary to stop your service.
  19.         }
  20.     }
  21. }
  22.  
Dec 23 '08 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 750
PRR
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?
Expand|Select|Wrap|Line Numbers
  1. qbConnect qbCnn = new qbConnect(); 
  2.  
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
Expand|Select|Wrap|Line Numbers
  1. protected override void OnStart(string[] args)
  2.        {
  3. try{
  4.             //qbConnect qbCnn = new qbConnect();
  5.            //qbCnn.qbTimer();
  6. }
  7.  
  8. catch(Exception e)
  9. {
  10. string error_file = System.Environment.ExpandEnvironmentVariables("%SystemDrive%").ToString() + @"\Error.txt";
  11.  
  12.             using (FileStream fs = new FileStream(error_file, FileMode.OpenOrCreate, FileAccess.Write))
  13.             {
  14.                 using (StreamWriter sw = new StreamWriter(fs))
  15.                 {
  16.                     sw.BaseStream.Seek(0, SeekOrigin.End);
  17.                     sw.WriteLine(e.Message.Tostring());
  18.  
  19.  
  20.                 }
  21.             }
  22.  
  23. }
  24.         }
  25.  
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...
Dec 24 '08 #2

P: 46
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.
Dec 24 '08 #3

Expert 100+
P: 750
PRR
@rottmanj
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?
Dec 25 '08 #4

Plater
Expert 5K+
P: 7,872
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?
Dec 29 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.