Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I handle sqlcmd.exe "Timeout expired" message, which doesn't appear to be an error?
    text
    copied!<p>When running the following command, sqlcmd.exe writes "Timeout Expired" to the console but the exit code it returns is 0.</p> <pre><code>sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerThan5Seconds.sql" -E </code></pre> <p>Please notice I'm purposely setting the querytimeout, -t, to 5 seconds. Also, I'm the -b argument, which I thought should return exit code 1 for errors. I've also tried the -r1 argument and the -m-1 argument to no avail.</p> <p>I've also looked at the <a href="http://technet.microsoft.com/en-us/library/ms190181%28v=sql.105%29.aspx" rel="nofollow noreferrer">Troubleshooting: Timeout Expired</a> article and noticed that it references an "Error: -2". The sqlcmd.exe documentation for all the arguments related to errors seem to only deal with error codes greater than 0, so perhaps "Timeout expired" is not an error? Also, no matter what arguments I've tried I only see "Timeout expired" as the output, no error code at all. </p> <p>Lastly, here are all the commands I've tried, only edited to protect server and database names:</p> <pre><code>C:\&gt;sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E Timeout expired C:\&gt;sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -r1 Timeout expired C:\&gt;sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -V16 Timeout expired C:\&gt;sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -m-1 Timeout expired C:\&gt;sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -m-1 Timeout expired C:\&gt;sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -r0 Timeout expired C:\&gt;sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -o "sqlError.txt" C:\&gt;notepad sqlError.txt #REM only "Timeout expired" was written to sqlError.txt C:\&gt;del sqlError.txt C:\&gt;sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -m-1 Timeout expired C:\&gt;sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -V-3 Sqlcmd: '-V -3': Severity level has to be a number between 1 and 25. C:\&gt;sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -V1 Timeout expired C:\&gt;sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -r1 Timeout expired </code></pre> <p><strong>Update:</strong> I should note I'm calling this from a C# console application via the Systems.Diagnostics.Process, so I'd like the ExitCode to be 1 if possible. I'm not sure if I can capture ERRORLEVEL.</p> <p><strong>Further Update:</strong> My machine is writing stderr to stdout for some reason, so I'm unable to test the validity of Stefan M's answer. I believe his answer is most likely correct as I've interpreted the documentation for sqlcmd.exe in the same manner. I have another question about why my machine is writing stderr to stdout <a href="https://stackoverflow.com/q/19300433/178207">here</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload