Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a homebrewed backup system for SQL Server 2008 Express on Windows Server 2008. A scheduled task runs a .bat file, which in turns calls sqlcmd.exe to run a .sql file that backs up all of the databases to .bak files. The scheduled task works fine if I right-click on it and click Run, but when the scheduled task runs in the middle of the night, sqlcmd.exe can't connect to the server, producing the error:

Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 :
Unable to complete login process due to delay in opening server connection.

I have the scheduled task set to run as myself, so the user is always the same. It's set to run whether I'm logged on or not, and set to store the password. It's also set to "run with highest privileges".

The sqlcmd.exe line of the batch script is:

"c:\program files\microsoft sql server\100\tools\binn\sqlcmd.exe" -s\SQLEXPRESS -i c:\web\backup_mssql.sql -o sqlcmd.log -b -E

I know that the docs say that the -s argument should be -S, but the command can't ever connect when I use -S.

The question is: why can this connect during the day but not when it runs automatically at night?

share|improve this question
Just to get rid of any doubt, can you try scheduling it during the day and seeing if it runs? It seems weird that it won't run at night. You right-clicking on it and running it seems to be the only difference so I'd try to schedule it at a time when you know it runs fine to see if time is the deciding factor here at all. – Sean Howat Sep 22 '10 at 14:56
Thanks for the suggestion! I had tried that and it seemed to work. It was some kind of timing issue. See my answer on this. – sbleon Sep 23 '10 at 16:02
Good stuff. These weird issues are always the hardest to figure out but often so easy to fix. Glad you got it working. – Sean Howat Sep 23 '10 at 16:56

I finally seem to have resolved the problem by changing the start time of the scheduled task from 1AM to 2AM. Something else must be heavily loading the system at 1AM so that the connection is really timing out.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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