I'm kind of lost on this one. I have a few DBs running on a Postgres instance, on a production machine with Windows Server 2008, and I want to schedule backups to the databases.

All I need are periodic dumps of the database. So I created a small .NET app, that loads a configuration file with the necessary data to locate each DB and a path to save the dump file. And this works well and as expected if I execute it manually through the command line. I get The necessary feedback, and the dump files are created. The application creates the command arguments dynamicly, and the database password is set in an enviroment variable before being executed:

Command Args: -ibv -Z3 -f "C:\Users\Administrator\Desktop\FlamingoRepo\BackupFiles\Cisne\Cisne20100311_104423.backup" -Fc -h localhost -U postgres -p 5432 Cisne

The problem occurs when I try to execute the same app from the TaskScheduler. I setup the scheduler to execute the app's .exe, and the history tab says it is executed and what not, but no file is created. And This is what I can't figure out. I scheduled the task as an Administrator (using the account I was logged in with), marked the checkbox related to highest privelages, and what not, but I still don't get any output (i.e. backup files), even though the history tab will say that it was executed and completed (in recent attempts, I'm not even getting any info in the history tab..). I've tried this on two machines (one standard and one with R2) with the same result.

Any suggestions would be apreciated!

2 Answers 2


Figured it out. But never expected it to be this.

I went through the logs and found some System.IO.FileNotFound Exceptions. Turns out my settings file (not the .config) wasn't being refered to correctly in code. In my config file, I had the file name defined ("settings.xml") and assumed it would be in the applications folder (and it is). I was refering to it this way:

xdoc.Load(System.Environment.CurrentDirectory.TrimTrailingPathSlash() + "\\" + ConfigurationManager.AppSettings["SettingsFile"]);

I use TrimTrailingPathSlash() to clean the last slashes to make sure I get it right. While executing the app directly would work (and System.Environment.CurrentDirectory would give me the correct path), when running in task sheduler, the path returned by System.Enviroment.CurrentDirectory surely wasn't, and I'm guessing it had the taskeng.exe's context, and therefore, wouldn't find the Settings.xml file in it's folder.

I cleaned the line, and set the full path in the config file, and that work.


It's obviously your target path of C:\Users\Administrator\Desktop that is causing this problem. Can you try a different target path, something like C:\MyBackups, and ensure that it's permissioned to allow write access by the account your scheduled task is running as.

Note that you could probably hack around this problem in other ways, but that would involve interfering with the way things are supposed to work on the OS, so it's not recommended.

  • Actually it isn't.. I just found the answer, and it was related to the path that my settings file was at. But I consider your point a good one. I used that folder just to test (I already had the folders created on the desktop), But a diferente folder (and even partition / disk) would be a whole lot better!
    – MytyMyky
    Mar 11, 2010 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.