2013-10-04 3 views
1

다음 명령을 실행 sqlcmd.exe를 콘솔에 "제한 시간이 만료되었습니다"하지만 반환 종료 코드는 내가 의도적 5, -t의 querytimeout을 설정하고있어주의하시기 바랍니다 0오류가 아닌 sqlcmd.exe "제한 시간 만료되었습니다"메시지를 처리하려면 어떻게합니까?

sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerThan5Seconds.sql" -E 

쓴다 초. 또한, 나는 오류에 대해 종료 코드 1을 반환해야한다고 생각하는 -b 인수입니다. 또한 -r1 인수와 -m-1 인수를 사용하지 않으려 고 시도했습니다.

나는 또한 Troubleshooting: Timeout Expired 문서를보고 "오류 : -2"를 참조하는 것으로 나타났습니다. 오류와 관련된 모든 인수에 대한 sqlcmd.exe 설명서는 0보다 큰 오류 코드 만 처리하므로 "시간 초과가 만료되었습니다"는 오류가 아닙니다. 또한, 내가 무슨 짓을했는지 상관없이, 나는 "Timeout expired"를 출력으로 볼뿐 오류 코드는 전혀 볼 수 없다.

마지막으로, 여기에 내가 해봤 모든 명령은, 전용 서버 및 데이터베이스 이름을 보호하기 위해 편집 :

C:\>sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E 
Timeout expired 

C:\>sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -r1 
Timeout expired 

C:\>sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -V16 
Timeout expired 

C:\>sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -m-1 
Timeout expired 

C:\>sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -m-1 
Timeout expired 

C:\>sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -r0 
Timeout expired 

C:\>sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -o "sqlError.txt" 

C:\>notepad sqlError.txt 

#REM only "Timeout expired" was written to sqlError.txt 

C:\>del sqlError.txt 

C:\>sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -m-1 
Timeout expired 

C:\>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:\>sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -V1 
Timeout expired 

C:\>sqlcmd.exe -X1 -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerTHan5Seconds.sql" -E -r1 
Timeout expired 

업데이트 : 내가 통해 C# 콘솔 응용 프로그램에서이 호출있어주의해야한다 Systems.Diagnostics.Process, 가능한 한 ExitCode 1 싶습니다. 내가 ERRORLEVEL을 포착 할 수 있는지 확실하지 않습니다.

추가 업데이트 : 내 컴퓨터가 어떤 이유로 stderr을 stdout에 쓰고 있으므로 스테판 남의 대답의 유효성을 테스트 할 수 없습니다. 나는 그의 대답이 sqlcmd.exe에 대한 문서를 같은 방식으로 해석 할 때 가장 정확하다고 믿습니다. 내 컴퓨터가 stderr을 stdout으로 작성하는 이유에 대한 또 다른 질문이 here입니다.

답변

1

-V-3은 사용할 수 없으며 가장 낮은 값은 -V1입니다. Combination with -b에서 원하는 결과를 얻어야합니다. 심각도가 -V보다 높은 경우에만 "ERRORLEVEL"값이 1로 설정됩니다.

sqlcmd.exe -X1 -b -S "[ValidServer]" -d "[ValidDatabase]" -t 5 -i "C:\test\ScriptThatRunsLongerThan5Seconds.sql" -E -V1 

을 그리고 시도 :

내 추측이 (테스트하지)입니다

echo %ERRORLEVEL% 

관련 부분은 다음과 같습니다

The value that is returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity level greater than 10; otherwise, the value returned is 0. If the -V option has been set in addition to -b, sqlcmd will not report an error if the severity level is lower than the values set using -V

-b

Specifies that sqlcmd exits and returns a DOS ERRORLEVEL value when an error occurs. The value that is returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity level greater than 10; otherwise, the value returned is 0. If the -V option has been set in addition to -b, sqlcmd will not report an error if the severity level is lower than the values set using -V. Command prompt batch files can test the value of ERRORLEVEL and handle the error appropriately. sqlcmd does not report errors for severity level 10 (informational messages).

If the sqlcmd script contains an incorrect comment, syntax error, or is missing a scripting variable, ERRORLEVEL returned is 1.

-m error_level

Controls which error messages are sent to stdout. Messages that have a severity level greater than or equal to this level are sent. When this value is set to -1, all messages including informational messages, are sent. Spaces are not allowed between the -m and -1. For example, -m-1 is valid, and -m -1 is not.

This option also sets the sqlcmd scripting variable SQLCMDERRORLEVEL. This variable has a default of 0.

-V error_severity_level

Controls the severity level that is used to set the ERRORLEVEL variable. Error messages that have severity levels greater than or equal to this value set ERRORLEVEL. Values that are less than 0 are reported as 0. Batch and CMD files can be used to test the value of the ERRORLEVEL variable.

01,235 http://technet.microsoft.com/en-us/library/ms162773.aspx에서
+0

답장을 보내 주셔서 감사합니다. 당신은 -V-3가 정확하지 않다는 것에 대해 옳았고, 이전의 테스트에는 -b와 -V1의 조합이 없었습니다. 방금 주사위가없는 조합을 시도했습니다. 여전히 종료 코드 0과 표준 출력 "만료되었습니다 \ r \ n". 시도해 줘서 고마워. – JustinP8

+0

'ERRORLEVEL'도 비어 있습니까? –

+0

사실은 잘 모르겠습니다. 나는 System.Diagnostics.Process를 사용하여 C#을 통해 sqlcmd.exe를 호출한다는 질문을 업데이트했다. – JustinP8