Debugging Windows Service

D

Derek Hart

As a newbie to Windows Service programming in VB.Net, I need some
clarification. I am writing a Windows Service that works with SQL Server. It
works fine as a console application, but when I run it as a service it is
having problems. I want to be able to debug it, so I placed this code in
the OnStart routine which allows me to break into the code:

System.Diagnostics.Debugger.Launch()
System.Diagnostics.Debugger.Break()

It looks like the only way I am allowed to debug the process is setting the
logon in the service (once it is installed of course) to the Local System
Account and choosing "Allow service to interact with desktop." But it looks
as if Local System does not have access to SQL Server, as I am getting an
"Unable To Connect To Server" error. Should Local System have access?

Derek
 
D

Dave Sexton

Hi Derek,

You don't even have to call Launch, just Break, and it shows a nifty little
dialog warning you that your program is in error and may be corrupt,
offering to allow you to debug it.

But I'm not sure if it'll work in a Windows Service.

Just thought you might like to know :)
 
C

Coder

If you run under Local System the service will have full permissions over
the machine (higher even than local admin) but it will have no permissions
in SQL Server.

I think what you want to do is run it under the account you need for SQL
access (you didn't say you were using Windows authentication so guessing
here) but make sure that same account is in the Debugger user group
(Computer Management -> Users and Groups -> Groups). Obviously putting it in
the administrators group will eliminate any permissions problems also.

Also, when you debug a service you need to use the attach to process option
in the debugger...

Cheers
 

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