以下代码使用xp_cmdshell执行bcp.exe。但是,即使命令/可执行文件失败,它仍继续运行以下代码。如果执行(我的特殊情况是运行sybase bcp)没有成功,如何引发异常?
declare @cmd varchar(max) = 'c:\sybase\bcp.exe ....'
begin try
exec xp_cmdshell @cmd
// .... do something if there is no error when executing @cmd
// Otherwise, STOP!
end try
begin catch
// report error
end catch
答案 0 :(得分:2)
以下是here中可能有帮助的示例......
答案 1 :(得分:0)
xp_cmdshell将(如果被调用的程序合作)如果程序成功结束则返回0,否则返回Null。我不认为尝试捕获会受到任何影响。