简体   繁体   English

如何为平面文件中的每个项目执行SSIS包?

[英]How can I execute an SSIS Package for every item in a Flat File?

I need to execute a package once for every item in flat file. 我需要为平面文件中的每个项目执行一次包。 The package's parameters will be a few of the current item's attributes. 包的参数将是当前商品的一些属性。 What is the best way to proceed? 最好的进行方法是什么? I'm assuming the last thing I do is place an Execute Package Task component inside of a Foreach Loop Container like below: 我假设我要做的最后一件事是将Execute Package Task组件放置在Foreach循环容器内,如下所示:

在此处输入图片说明

Simple Solution 简单的解决方案

  1. First of all you have to create a Package variable of type Object 首先,您必须创建Object类型的Package变量
  2. Add a script task that loop over flat file and convert it to a DataTable or List(of T) and store it into the Object variable. 添加一个脚本任务,该任务遍历平面文件并将其转换为DataTableList(of T) ,并将其存储到Object变量中。
  3. Connect the Script Task to the foreach loop you are using 将脚本任务连接到您正在使用的foreach循环
  4. In the foreach loop container select the enumeration type to Ado enumerator and select the Object variable as Source and map the columns you want to use in the execute package task to variables 在foreach循环容器中,将枚举类型选择为Ado枚举器,然后选择Object变量作为Source并将要在execute package task使用的列映射到变量

Reading Flat File into DataTable 将平面文件读入DataTable

you can refer to one of the following links to learn more: 您可以参考以下链接之一以了解更多信息:

Side Note: If you need more details, give me a reply 旁注:如果您需要更多详细信息,请给我回复

Each item had three attributes: username, password, and exactAccountName 每一项都有三个属性:用户名,密码和exactAccountName

These were then used to execute an SSIS package with each login credential. 然后,将它们用于执行具有每个登录凭据的SSIS程序包。

In order to achieve this, do the following: 为此,请执行以下操作:

  1. Create a package variable of type Object in the master package. 在主包中创建Object类型的包变量。
  2. Add a script task that loop over flat file and convert it to a DataTable or List(of T) and store it into the Object variable. 添加一个脚本任务,该任务遍历平面文件并将其转换为DataTable或List(of T),并将其存储到Object变量中。 (This step is from Hadi's answer) (这是哈迪的回答)
  3. Create a foreach loop to execute next. 创建一个foreach循环以下一步执行。
  4. In the foreach loop container select the enumeration type to Ado enumerator and select the Object variable as Source. 在foreach循环容器中,将枚举类型选择为Ado枚举器,然后选择Object变量作为Source。 (Also from Hadi's answer) (也来自哈迪的回答)
  5. Put a Script Task and Execute Package Task in the foreach loop. 将脚本任务和执行程序包任务放入foreach循环中。 Like so: 像这样: 在此处输入图片说明
  6. Create three string variables in the master package for username, password, and exactAccountName. 在主软件包中为用户名,密码和exactAccountName创建三个字符串变量。
  7. Populate the main function of the Script Task with code like this: 使用以下代码填充“脚本任务”的主要功能: 在此处输入图片说明
  8. Set the parameters of the child package to be the variables specified by the Script Task and you're done! 将子程序包的参数设置为脚本任务指定的变量,就可以完成!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM