检测未映射到目标的源中的新列并在 SSIS 中失败 [英] Detect new column in source not mapped to destination and fail in SSIS

查看:38
本文介绍了检测未映射到目标的源中的新列并在 SSIS 中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果源表中的列在目标表中没有对应的列,或者至少是故意不包含它,我如何导致 SSIS 2017 包失败?

How can I cause an SSIS 2017 package to fail if a column in the source table does not have a corresponding column in the destination table, or at least a deliberate decision to not include it?

我在两个名为 test 的表中创建了一个表,其中包含一列 testcol.SSIS 传输数据.现在我向源添加了一个 testcol2,但没有向目标添加一个 testcol2.该作业仍然按照今天的处理方式运行良好,但我希望它失败并报告未映射的列错误.

I made a table in both called test with one column, testcol. SSIS transfers the data. Now I added a testcol2 to the source, but not to the destination. The job still runs fine the way it's handled today, but I want that to fail and report an unmapped column error.

推荐答案

更新 1

在对这个问题做了更多研究之后,看起来 ValidatExternalMetadata 没有做你想要的.它只会跟踪所选列上发生的元数据更改.

基于此,我认为 SSIS 中没有选项可以执行此操作,您必须将自定义验证添加到包中,例如:

Based on that, i don't think there is an option in SSIS to do this, you must add your custom validation to the package such as:

  1. 声明一个包含列数的变量(当你设计包时)然后添加一个执行 SQL 任务来检查当前的列数 (SELECT Count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?).如果计数不相同,则抛出异常.
  2. 创建一个包含源表列的引用表并添加一个执行 SQL 任务以检查是否有新添加的列 (SELECT Count(*) FROM Information_schema.Column T1 LEFT JOIN Source Columns T2 ONT1.COLUMN_NAME = T2.Column_name WHERE T2.Column_Name IS NULL) 然后检查结果是否 > 0 然后抛出异常.
  3. 使用执行 SQL 任务从数据库架构审计表中读取:

<小时>

初始答案

您可以通过将 OLEDB Source ValidatExternalMetadata 属性设置为 True 来实现这一点.


Initial Answer

You can achieve this by setting the OLEDB Source ValidatExternalMetadata property to True.

当添加新列时,它应该抛出类型异常.

When new columns are added it should throw an exception of type.

VS_NEEDSNEWMETADATA

VS_NEEDSNEWMETADATA

请注意,执行包时这可能需要额外的时间.

Be aware that this may take additional time when executing the package.

更多信息,请参考:

这篇关于检测未映射到目标的源中的新列并在 SSIS 中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆