Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssis 如何在Integration Services中手动使包失败?_Ssis - Fatal编程技术网

Ssis 如何在Integration Services中手动使包失败?

Ssis 如何在Integration Services中手动使包失败?,ssis,Ssis,我正在SSIS包中运行执行SQL任务语句。执行SQL任务正在运行SQL并检查表中的行数是否超过1000行。如果它们的行数少于1000行,我希望包失败 如何在SQL语句内部强制执行失败?好的,SSIS中的任务在出错时失败。因此,如果您的执行SQL任务中有这样的语句: declare @count int select @count = select count(*) from my_table if @count < 1000 begin raiserror('Too few row

我正在SSIS包中运行执行SQL任务语句。执行SQL任务正在运行SQL并检查表中的行数是否超过1000行。如果它们的行数少于1000行,我希望包失败


如何在SQL语句内部强制执行失败?

好的,SSIS中的任务在出错时失败。因此,如果您的执行SQL任务中有这样的语句:

declare @count int
select @count = select count(*) from my_table
if @count < 1000
begin
    raiserror('Too few rows in my_table',16,1)
end
else
begin
    -- Process your table here
end

您应该会得到想要的结果。

您需要将属性FailPackageOnFailure设置为true。尝试检索特定任务的属性FailPackageOnFailure并将值指定为true。因此,该包将失败。

您可以创建如下自定义错误消息

EXEC sp_ADDMESSAGE 
        @msgnum=55555,
        @severity=1,
        @msgtext='Threshold condition failed. The package execution has been terminated.'
然后可以使用Raiserror调用此错误

Raiserror (55555,20,-1) WITH LOG

您需要在此处输入大于18的数字表示严重性为20。您需要对此具有管理员权限。别忘了使用LOG,我喜欢使用脚本任务强制失败。这真的很容易

1添加脚本任务

2将自动生成的代码行更改为:

Dts.TaskResult = (int)ScriptResults.Success; 

就这样

创建一个用户变量。将记录计数存储在该变量User::Rcnt中 只需使用发送邮件任务并定义工作流程。
在前面的constraint User::RcntYou中,您还必须正确设置包属性,并可能在my_表中设置'failparentonerror'raiserror'的行太少,16,1这就完成了!我想这不是一个SSIS问题,而是一个SQL问题。谢谢。请注意,错误级别必须足够高,例如raiserror“my_表中的行太少”,1,1不起作用
Dts.TaskResult = (int)ScriptResults.Failure;