我正在調用批處理文件上的SQL Server腳本,但我需要在批處理文件中獲取錯誤(當腳本失敗時),我該怎麼辦?如何在批處理文件中獲取SQL Server腳本錯誤文件
這是批處理文件:
sqlcmd -S HOST -U User -P password -i test.sql
echo %errorlevel%
,這是腳本文件(的Test.sql):
USE TrainingSitecore_Web
go
SELECT * FROM items
go
RAISERROR ('This is a test Error.',-- Message text.
16,-- Severity.
1 -- State.
);
有意義嗎?
將在下面的鏈接最後的答案是你的情況? http://dba.stackexchange.com/questions/77298/how-to-make-sqlcmd-return-an-errorlevel-other-than-0-when-the-sql-script-fails – knkarthick24 2014-11-21 17:37:40
是的男人,它是工作:) – 2014-11-21 18:32:10