以编程方式生成包Building Packages Programmatically

适用对象:是SQL Server,包含 Linux 版 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server, including on Linux yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

如果您需要动态创建包,或需要在开发环境之外管理和执行 Integration ServicesIntegration Services 包,则可以采用编程方式对包进行操作。If you need to create packages dynamically, or to manage and execute Integration ServicesIntegration Services packages outside the development environment, you can manipulate packages programmatically. 如果采用这种方法,则有一系列选择:In this approach, you have a continuous range of options:

  • 加载并执行现有包,不进行修改。Load and execute an existing package without modification.

  • 加载现有包,对其进行重新配置(例如,指定一个不同的数据源),然后执行。Load an existing package, reconfigure it (for example, for a different data source), and execute it.

  • 创建一个新包,添加并配置组件(逐个对象和属性),保存并执行。Create a new package, add and configure components object by object and property by property, save it, and execute it.

您可以使用 Integration ServicesIntegration Services 对象模型,以任何托管编程语言编写可创建、配置和执行包的代码。You can use the Integration ServicesIntegration Services object model to write code that creates, configures, and executes packages in any managed programming language. 例如,您可能希望创建元数据驱动的包,它们可以基于所选数据源及其表和列,配置它们的连接或数据源、转换和目标。For example, you may want to create metadata-driven packages that configure their connections or their data sources, transformations, and destinations based on the selected data source and its tables and columns.

本节逐行介绍并演示如何以编程方式创建和配置包。This section describes and demonstrates how to create and configure a package programmatically line by line. 如果选择复杂性最低的包编程方式,只需加载并运行现有包,不需要进行以编程方式运行和管理包中所介绍的修改。At the less complex end of the range of package programming options, you can simply load and run an existing package without modification as described in Running and Managing Packages Programmatically.

这里没有介绍一种中间方式,即将一个现有包加载为模板,对其进行重新配置(例如,指定一个不同的数据源),然后执行。An intermediate option not described here is that of loading an existing package as a template, reconfiguring it (for example, for a different data source), and executing it. 您也可以使用本节中的信息,修改包中的现有对象。You can also use the information in this section to modify the existing objects in a package.

备注

将现有包用作模板并修改数据流中的现有列时,您可能必须删除现有列并调用受影响组件的 ReinitializeMetaData 方法。When you use an existing package as a template and modify existing columns in the data flow, you may have to remove existing columns and call the ReinitializeMetaData method of affected components.

本节内容In This Section

以编程方式创建包Creating a Package Programmatically
介绍如何以编程方式创建包。Describes how to create a package programmatically.

以编程方式添加任务Adding Tasks Programmatically
介绍如何向包中添加任务。Describes how to add tasks to the package.

以编程方式连接任务Connecting Tasks Programmatically
介绍如何基于前一个任务或容器的执行结果来控制包中容器或任务的执行。Describes how to control execution of the containers and tasks in a package based on the result of the execution of a previous task or container.

以编程方式添加连接Adding Connections Programmatically
介绍如何向包中添加连接管理器。Describes how to add connection managers to a package.

以编程方式使用变量Working with Variables Programmatically
介绍如何在包执行期间添加和使用变量。Describes how to add and use variables during package execution.

以编程方式处理事件Handling Events Programmatically
介绍如何处理包和任务事件。Describes how to handle package and task events.

以编程方式启用日志记录Enabling Logging Programmatically
介绍如何为包或任务启用日志记录,以及如何对日志事件应用自定义筛选器。Describes how to enable logging for a package or task, and how to apply custom filters to log events.

以编程方式添加数据流任务Adding the Data Flow Task Programmatically
介绍如何添加和配置数据流任务及其组件。Describes how to add and configure the Data Flow task and its components.

以编程方式查找数据流组件Discovering Data Flow Components Programmatically
介绍如何检测本地计算机上安装的组件。Describes how to detect the components that are installed on the local computer.

以编程方式添加数据流组件Adding Data Flow Components Programmatically
介绍如何向数据流任务添加组件。Describes how to add a component to a data flow task.

以编程方式连接数据流组件Connecting Data Flow Components Programmatically
介绍如何连接两个数据流组件。Describes how to connect two data flow components.

以编程方式选择输入列Selecting Input Columns Programmatically
介绍如何从数据流中的上游组件提供给组件的输入列中选择输入列。Describes how to select input columns from those that are provided to a component by upstream components in the data flow.

以编程方式保存包Saving a Package Programmatically
介绍如何以编程方式保存包。Describes how to save a package programmatically.

参考Reference

Integration Services 错误和消息引用Integration Services Error and Message Reference
列出预定义的 Integration ServicesIntegration Services 错误代码及其符号名称和说明。Lists the predefined Integration ServicesIntegration Services error codes with their symbolic names and descriptions.

用脚本扩展包Extending Packages with Scripting
讨论如何使用脚本任务扩展控制流,以及如何使用脚本组件扩展数据流。Discusses how to extend the control flow by using the Script task, and how to extend the data flow by using the Script component.

用自定义对象扩展包Extending Packages with Custom Objects
讨论如何创建用于多个包的编程自定义任务、数据流组件以及其他包对象。Discusses how to create program custom tasks, data flow components, and other package objects for use in multiple packages.

以编程方式运行和管理包Running and Managing Packages Programmatically
讨论如何枚举、运行和管理包以及存储包的文件夹。Discusses how to enumerate, run, and manage packages and the folders in which they are stored.

外部资源External Resources

另请参阅See Also

SQL Server Integration ServicesSQL Server Integration Services