开发者

BCP exits with code 0

开发者 https://www.devze.com 2023-03-18 03:44 出处:网络
When running BCP from my Java application it exits with status code 0 when 1 is expected. I run bcp with an invalid combination of data and formatting file and bcp gives the following error:

When running BCP from my Java application it exits with status code 0 when 1 is expected. I run bcp with an invalid combination of data and formatting file and bcp gives the following error:

Starting copy...
SQLState = 22005, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Invalid character value for cast  specification

BCP copy in failed

BCP however exits with exit code 0 and not 1, as i suspect. Now it is extremely difficult to see if something failed while running BCP. Exitting with the right code works once they match to some degree (like same delimiters).

Command

PS C:\Users\feh\Desktop> bcp integrate_test.dbo.AS_LOADER_DELIMITED in .\data.dat -S "10.0.0.161\SQL2K5,1048" -U user -P pass -f .\formatting.ctl -m 1

Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Unexpected EOF encountered in BCP data-file

0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 1
PS C:\Users\feh\Desktop> $lastexitcode
0

开发者_C百科How can i validate a formatting file to the data and get a exit code 1 when they do not match?


If the bcp is "in" the consider using BULK INSERT. This does the same as bcp but can be trapped using SQL Server TRY/CATCH or normal exception handling

Otherwise, are you trapping %ERRORLEVEL% and not some other code?

0

精彩评论

暂无评论...
验证码 换一张
取 消