Hi,
I want to run a window service as soon as the system get start automatically. I have made a service it is working properly but the problem is that when i shutdown the system and come next day and start the system, the service is not started. I have to manually start the service but when i try and check by restarting the system, the service is started only. Please can anyone suggest!!!
Loading


Guest UserRank #1,422 · 1.2K reputationPosted May 13, 2011, 5:07 AM EDT
http://joefreeman.co.uk/blog/2010/03/creating-a-setup-project-for-a-windows-wcf-service-with-visual-studio/
When you run the msi that will be created when you build your setup project, the information in ProjectInstaller1 will be used to establish the dependency.
VulpesRank #55 · 29.2K reputationPosted May 11, 2011, 7:17 AM EDT
Vijay YadavRank #1,637 · 943 reputationPosted May 11, 2011, 7:24 AM EDT
I have set the StartType propety to Automatic but hten also it is nt getting started.
Any other idea?
VulpesRank #55 · 29.2K reputationPosted May 11, 2011, 7:43 AM EDT
I'd make sure that you've installed all the latest updates and, if you're using Vista, I'd see if there's anything which helps in this thread (http://social.technet.microsoft.com/forums/en-US/itprovistasetup/thread/cc3ce627-9a7e-4887-a793-edd66b70ea3e/).
Guest UserRank #1,422 · 1.2K reputationPosted May 11, 2011, 8:24 AM EDT
One possibility is that the service is attempting to access areas of the file system that the account it's running under does not have access to. As a test, try changing the service's logon account to one with local admin rights to see if that fixes the problem (using the "Log On" tab of the service properties dialog). If the service runs normally, then you should create another local account with the minimum permissions it needs to access those areas of the file system. Don't let it use an admin account for production use as that may introduce security issues.
Sam HobbsRank #107 · 20.5K reputationPosted May 11, 2011, 5:49 PM EDT
Mahesh ChandRank #1 · 393.3K reputationPosted May 11, 2011, 7:05 PM EDT
Find your services name, right click on it, select Properties.
On General tab, make Startup Type = Automatic.
Vijay YadavRank #1,637 · 943 reputationPosted May 12, 2011, 4:19 AM EDT
And Mahesh, i done this but then also it is not working. You can see the images of the service in the attached file.
One is when i start the service and another is when i shutdown and start the system again but service didn't get start.
Please help!!!
Vijay YadavRank #1,637 · 943 reputationPosted May 12, 2011, 4:47 AM EDT
and
@Sam i also don't understand what's there in system event logs.
Guest UserRank #1,422 · 1.2K reputationPosted May 12, 2011, 1:48 PM EDT
Guest UserRank #1,422 · 1.2K reputationPosted May 12, 2011, 1:51 PM EDT
You really should add some error logging to your service. Some possibilities are log4net and Elmah.
You won't be able to fix your problem until you find out what's causing it, and to do that you have to catch the exceptions being thrown and track down their cause(s).
Mahesh ChandRank #1 · 393.3K reputationPosted May 12, 2011, 1:56 PM EDT
This is possible that your service is trying to run but getting an exception. If an exception occurs, it won't start. Try to put a try..catch in your code within the service and if exception occurs, write in a local text file. This was one of the way I used to diagnose my windows service problems.
Suthish NairRank #92 · 22.8K reputationPosted May 12, 2011, 10:19 PM EDT
An alternative solution
Vijay YadavRank #1,637 · 943 reputationPosted May 13, 2011, 3:28 AM EDT
Thanks for your kind reply.
@Suthish- I tried your way but it doesn't worked out.
And the problem is that onstart of service i am retrieving data from database.
As John and Mahesh suggested for exception handling, I am writing the exception in the local file and it is showing
"Cannot open database "database_ name" requested by the login. The login failed. Login failed for user 'sa'" on start of the computer. That means it is not able to retrieve the data on start of the service when the system start again but now the service is getting started as i changed the account from network service to local system. Please help!
Guest UserRank #1,422 · 1.2K reputationPosted May 13, 2011, 4:34 AM EDT
It's also possible that your service is starting before the SQL Server service has been started. If that's the case, then you will need to establish a dependency for your service so that it won't try to start before SQL Server. You can do this by creating an installer (i.e. a setup project) for your service.
Vijay YadavRank #1,637 · 943 reputationPosted May 13, 2011, 4:41 AM EDT
You are right my service is geeting start before sql server starts. As you suggested to create an installer (i.e. a setup project) for the service. As far as i understood, i have to just create a setup. Can you please ellaborate the same. Thanks a lot!
Guest UserRank #1,422 · 1.2K reputationPosted May 13, 2011, 5:13 AM EDT
Guest UserRank #1,422 · 1.2K reputationPosted May 13, 2011, 5:18 AM EDT
The serviceInstaller1 component is where you set the DisplayName and Description of your service (the text that appears in the Administrative Tools->Services list), and the startup type (manual/automatic/disabled). You should still use Automatic, but with the dependency to SQL Server in place it should start correctly.
Vijay YadavRank #1,637 · 943 reputationPosted May 13, 2011, 6:08 AM EDT
Thanks a lot!!!
It is working fine now... :)
Guest UserRank #1,422 · 1.2K reputationPosted May 13, 2011, 7:30 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted May 13, 2011, 7:53 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 13, 2011, 8:07 AM EDT
Vijay YadavRank #1,637 · 943 reputationPosted May 15, 2011, 10:45 PM EDT