Reputation: 1968
Am trying to develop a windows service which listens to a rabbitMQ listener and stores the messages it listens into database...the code is working perfectly in debug mode but is not working as a windows service....
Debug and service code:
if (!Environment.UserInteractive)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new RabService()
};
ServiceBase.Run(ServicesToRun);
}
else
{
var service = new RabService();
service.OnStart(null);
Thread.Sleep(Timeout.Infinite);
}
Any inputs would be appreciated!
Upvotes: 0
Views: 352
Reputation: 5179
Please cross check whether you have done the following steps:
After creating the windows service project go to the service class's design view(just double click the service1.cs class).
In the design view right click and select Add Installer. This will create an Installer class named ProjectInstaller.cs. Without ProjectInstaller.cs or any error in configuring ProjectInstaller.cs may result in non-showing of the service in service console.
Go to the design view of ProjectInstaller.cs you will find two installers there->
a. ServiceInstaller1
b. ServiceProcessInstaller1
Right click ServiceInstaller1 and go to the properties tab
a. Edit the ServiceName with the name you want to see your service in the service console
b. Change the StartType to Automatic.
Right click ServiceProcessInstaller1 and go to the properties tab
a. Change the account to LocalService
Save and try it.
Hope this will help you.
Upvotes: 1
Reputation: 1001
If your connection string to the database is using windows security, it is possible that your debug user is able to access the database. But the windows service runs under another user.
So just to discard this option I would recommend the following:
Then restart the windows service and debug it.
Regards,
Upvotes: 2