why won't my service stay started

L

Lance Colton

it only behaves as expected if i edit the service to run under the system
account and enable the "allow service to interact with desktop" option. if i
run without that enabled or run it under my currently logged on account it
gives an error saying the service started and then stopped right away. i
just created a new vb.net service and put a timer in it and set the interval
and put some code in the Timer1_Elapsed... the timer is just the default
one of type system.timers.timer , is there another type i should be using
here?

also how come when i hit the debug button it tells me you cannot start the
service from the command line or debugger, and if i wait a few seconds
before hitting ok my timer event fires and i can debug it fine?? is there
some other way to debug it properly?

thanks in advance
 
V

Vincent Finn

it only behaves as expected if i edit the service to run under the system
account and enable the "allow service to interact with desktop" option. if i
run without that enabled or run it under my currently logged on account it
gives an error saying the service started and then stopped right away. i
just created a new vb.net service and put a timer in it and set the interval
and put some code in the Timer1_Elapsed... the timer is just the default
one of type system.timers.timer , is there another type i should be using
here?

What code do you have in the timer?
The most likely thing is that the timer fires and what it does isn't
allowed without desktop interaction
also how come when i hit the debug button it tells me you cannot start the
service from the command line or debugger, and if i wait a few seconds
before hitting ok my timer event fires and i can debug it fine?? is there
some other way to debug it properly?

You can run it from the Service Control Manager and the use "Tools ->
Debug Processes" to attach to it

Vin
 
L

Lance Colton

code in the timer:

==============
Dim myReader As System.Data.SqlClient.SqlDataReader
SqlConnection1.Open()
SqlCommand1.CommandText = "xxxxxxxxxxxxxxxx"
myReader = SqlCommand1.ExecuteReader()
While myReader.Read()
Debug.WriteLine(myReader.Item(0) & myReader.Item(1) & myReader.Item(2))
End While
myReader.Close()
SqlConnection1.Close()
===============
sure, that debug.writeline stuff isn't going to do anything without the IDE
being open, so you think the exe or windows knew this and 'optimized' my
service by removing the whole timer since it does nothing?

maybe my database connection doesn't work properly with no desktop
interaction and its getting an error and closing right away, or something.

thanks for the info on how to debug it though...
 
V

Vincent Finn

code in the timer:

==============
Dim myReader As System.Data.SqlClient.SqlDataReader
SqlConnection1.Open()
SqlCommand1.CommandText = "xxxxxxxxxxxxxxxx"
myReader = SqlCommand1.ExecuteReader()
While myReader.Read()
Debug.WriteLine(myReader.Item(0) & myReader.Item(1) & myReader.Item(2))
End While
myReader.Close()
SqlConnection1.Close()
===============
sure, that debug.writeline stuff isn't going to do anything without the IDE
being open, so you think the exe or windows knew this and 'optimized' my
service by removing the whole timer since it does nothing?

Doubt if it is allowed do that since it can't tell that the function
calls don't do other things
and if the code was all removed then your service would run perfectly
(doing nothing but still running)
maybe my database connection doesn't work properly with no desktop
interaction and its getting an error and closing right away, or something.

sounds more likely
might be worth rephrasing the question with emphasis on the
SqlDataReader class with no desktop
I have never used it so I can't really offer any suggestions

Vin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top