1

We have a Windows Service that checks a configuration file, and based on those settings, starts a new Process (let's call this ClusterProcess) which connects to a database and does the actual functionality.

There is a test project, that cuts out the Windows Service's part in the play, and just provides ClusterProcess with the necessary settings.

For our current test environment, we have the database on a cloud and I would say, rather restricted permissions.

My problem is this: when I run the test project, ClusterProcess gets its settings and things happen on the database. However, when I run the Windows Service, nothing gets changed on the database.

I've been using log4net to try and see where things fall over, but it seems to fail silently.

So the Windows Service calls this:

_ClusterRunnner.StartAllClusters();

In this method mentioned above, this is (amongst other things) what happens, and I get both log statements:

            _ClusterProcesses = new  List<Process>();  
            log.Debug("Cluster Name: " + cluster.Name + " ConfigPath: " + _ConfigPath);
            _ClusterProcesses.Add(Process.Start(startInfo));
            log.Debug("After process spawn.");

Okay, so the Process that it should start is ClusterProcess.exe, and in the Main method of that project I don't get any of the log statements that should be given, for instance:

            log.Debug("Going to Start Processing");
            _ClusterProcessor = new ClusterProcessor(config);
            _ClusterProcessor.StartProcessing();
            log.Debug("Finished Processing");

With log4net I have a special logger for ClusterProcess.exe (two appenders, a RollingFileAppender and an AdoNetAppender) and similar appenders for the Windows Service. (The Windows Service process holds a lock to its RollingFileAppender, so I had to create a special one for ClusterProcess.exe. The AdoNetAppenders are for nicely formatted logs after the connection to the database has been made.)

But now, the test project just calls this directly:

        ClusterProcessor x = new ClusterProcessor(config);
        x.StartProcessing();

and it works! I get the log statements in StartProcessing() and the database is changed.

So any ideas?

Igavshne
  • 699
  • 7
  • 33
  • What kind of error reporting do you have in the service? Would you find out about errors? – usr Jul 25 '15 at 14:19
  • Anything in the windows log? What user is the service running under - does it work if you give the service user admin privelages? (not suggesting that's a fix, but might help troubleshooting) – MarcE Jul 25 '15 at 14:20
  • Yes, I would find out about errors, and I had a brief look in the Windows log, but couldn't see anything. The issue was fixed when the Service was run with administrator rights. – Igavshne Jul 28 '15 at 17:10

1 Answers1

0

From my experience with services they run with very limited rights. So if your Test(possible windows application) runs perfectly then I guess it has something to do with user rights.

I guess you can't realy access the filesystem so if your logger writes to a place on the harddrive you should think about the windows event log --> Write to Windows Application Event Log without registering an Event Source

To try if it has something to do with user rights just open your service in the windows service settings and let it log on as your administrator account and see if it has something to do with this.

Community
  • 1
  • 1
Bongo
  • 2,933
  • 5
  • 36
  • 67