469,336 Members | 5,746 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

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
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
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.         }
  10.         protected override void OnStart(string[] args)
  11.         {
  12.             //qbConnect qbCnn = new qbConnect();
  13.             //qbCnn.qbTimer();
  14.         }
  16.         protected override void OnStop()
  17.         {
  18.             // TODO: Add code here to perform any tear-down necessary to stop your service.
  19.         }
  20.     }
  21. }
Dec 23 '08 #1
4 3156
750 Expert 512MB
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(); 
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. }
  8. catch(Exception e)
  9. {
  10. string error_file = System.Environment.ExpandEnvironmentVariables("%SystemDrive%").ToString() + @"\Error.txt";
  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());
  20.                 }
  21.             }
  23. }
  24.         }
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
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
750 Expert 512MB
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
7,872 Expert 4TB
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.

Similar topics

2 posts views Thread by Rajesh Abraham | last post: by
2 posts views Thread by Razzie | last post: by
reply views Thread by tshad | last post: by
7 posts views Thread by Joseph Geretz | last post: by
5 posts views Thread by eliasen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.