SSIS ForEach 循环未迭代文件夹中的所有项目

问题描述 投票:0回答:1

我的一个文件夹中有 4 个 Excel 文件。 2 个有同名的单张纸,另外 2 个各有 2 张纸(我想要的数据具有相同的名称)。

  • 我在 SSIS 中使用 ForEach 循环来迭代文件夹中的所有文件。
  • 我将初始路径分配给变量,即 ExcelFilePath。
  • 我在循环容器中配置了此变量,以便它可以保存文件夹中所有文件的路径。
  • 我已将此变量作为 Excel 连接管理器字符串中的 Excel 文件路径属性中的表达式传递。

这是我的项目设计:

但是,当我执行包时,只有第一个数据流对象(即分支)成功执行。我认为这是因为它的路径被硬编码在我的变量中。所有其他数据流对象都会失败。

执行结果:

日志:

Error: 0xC004701C at COUNTRY_INFO, SSIS.Pipeline: OLE DB
Destination.Inputs[OLE DB Destination Input].Columns[COUNTRY_CODE] has
lineage ID 255 that was not previously used in the Data Flow task.
Error: 0xC004706B at MG_SEND, SSIS.Pipeline: "Excel Source" failed
validation and returned validation status "VS_ISBROKEN". 
Error: 0xC004700C at MG_SEND, SSIS.Pipeline: One or more component failed
validation. Error: 0xC0024107 at MG_SEND: There were errors during
task validation.
Error: 0xC004706B at COUNTRY_INFO, SSIS.Pipeline: "OLE DB Destination"
failed validation and returned validation status "VS_NEEDSNEWMETADATA".

我已将每个组件的 DelayValidation 设置为 True。 连接字符串属性中的 RetainSameConnection 为 False。

编辑: 尝试添加带有优先约束箭头的序列容器,以便路径仅重定向到相应的 DFT。所有组件的延迟验证均设置为 True。

设计: Current Package Design

执行结果如下: Execution Result After Changes

日志:

    Error: 0xC001000E at Package1: The connection "" is not found. This error is thrown by Connections collection when the specific connection element is not found.
Error: 0xC02020EA at Package1, Log provider "SSIS log provider for SQL Server": The connection manager "" is not found. A component failed to find the connection manager in the Connections collection.
Error: 0xC001000E at Package1: The connection "" is not found. This error is thrown by Connections collection when the specific connection element is not found.
Error: 0xC02020EA at Package1, Log provider "SSIS log provider for SQL Server": The connection manager "" is not found. A component failed to find the connection manager in the Connections collection.
Warning: 0x80019002 at Package1: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (2) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
Information: 0x4004300A at BRANCHES, SSIS.Pipeline: Validation phase is beginning.
Warning: 0x800470C8 at BRANCHES, Excel Source [26]: The external columns for Excel Source are out of synchronization with the data source columns. The column "BRANCH_CODE" needs to be added to the external columns.
The column "BRANCH_NAME" needs to be added to the external columns.
The column "AGENT_ID" needs to be added to the external columns.
The column "MAKER" needs to be added to the external columns.
The column "CHECKER" needs to be added to the external columns.
The column "CREATE_DATE" needs to be added to the external columns.
The column "BRANCH_COUNTRY" needs to be added to the external columns.
The column "CREATE_STATUS" needs to be added to the external columns.
The Excel Source.Outputs[Excel Source Output].ExternalColumns[IS_RECEIVE_ACTIVE] needs to be removed from the external columns.
The Excel Source.Outputs[Excel Source Output].ExternalColumns[IS_SEND_ACTIVE] needs to be removed from the external columns.
The Excel Source.Outputs[Excel Source Output].ExternalColumns[BASE_RECEIVE_CURRENCY] needs to be removed from the external columns.
The Excel Source.Outputs[Excel Source Output].ExternalColumns[COUNTRY_NAME] needs to be removed from the external columns.
The Excel Source.Outputs[Excel Source Output].ExternalColumns[COUNTRY_LEGACY_CODE] needs to be removed from the external columns.
The Excel Source.Outputs[Excel Source Output].ExternalColumns[COUNTRY_CODE] needs to be removed from the external columns.
Error: 0xC004706B at BRANCHES, SSIS.Pipeline: "Excel Source" failed validation and returned validation status "VS_NEEDSNEWMETADATA".
Error: 0xC004700C at BRANCHES, SSIS.Pipeline: One or more component failed validation.
Error: 0xC0024107 at BRANCHES: There were errors during task validation.

请注意,ExcelFilePath 变量最初设置为 BRANCHES 路径。另外,我已经通过脚本任务测试了容器,它确实在文件夹中的所有路径上循环。

sql-server excel ssis etl foreach-loop-container
1个回答
0
投票

数据流的工作原理基于设计时前提,即完全符合设计时值的源数据将被超快速地加载并推入也匹配设计时值的目的地。

SSIS 不能成为目标引擎的通用源。产品不是这样设计的。

每次执行包时都会发生的一个步骤是验证。验证步骤的目标是,如果某些内容不符合构建数据流的合同,则尽早失败。

您可以将在包启动时进行的验证更改为在task启动时进行。这样,如果您从前驱步骤中创建的源中提取数据,则该包将仅在任务开始时运行验证。

此处发生的情况是,您拥有的一个 Excel 连接管理器对第一个数据流任务有效,但对其余任务无效。为了解决这个问题,您需要指示 SSIS 等待验证。

综上所述,为了让您的设计按预期工作:

  • 将 DelayValidation 的 Excel 连接管理器属性更新为 True
  • 更新 4 个数据流任务,将 DelayValidation 属性设置为 True

现在,这 5 项更改还不足以让您的流程发挥作用。因为当找到 Branches 文件时,COUNTRY_INFO 数据流仍然会触发并且元数据不匹配。

要纠正这个问题,您需要有一个前置任务,该任务不执行任何操作,而只是充当锚点。我发现序列容器在这里工作得很好

请注意,绿色连接器在序列容器和数据流任务之间有一点 f(x)。那是因为我已将求值操作更改为“表达式和约束”。

约束是拼图的最后一块。当名称与数据流匹配时,您需要使此条件为真。

假设数据流中的单词存在于文件名中,该文件名在 Foreach 枚举器中显示为变量 @[User::ExcelFilePath]

BRANCHES 的表达式类似于

FINDSTRING(UPPER(@[User::ExcelFilePath]), "BRANCHES" , 1 ) > 0

即:将Excel File Path 的值转换为全部大写。如果全大写的单词 BRANCHES 位于文件路径中,则 FindString 方法将返回一个从 1 或更大的数字开始。如果 FindString 中的数字非零,则为 TRUE,否则为 false

对每个分支重复此模式。

发生的情况是,只有当预期的文件被枚举(然后验证)时,路径才会亮起。错误的文件路径不会亮起,因此不会验证失败。

© www.soinside.com 2019 - 2024. All rights reserved.