SQL 代理作业如何将像 User::filePath 这样的变量传递给 运行 SSIS 包中的脚本?

How does a variable like `User::filePath` get passed to a script in an SSIS package that's run by an SQL Agent Job?

如果我直接看脚本,使用 CREATE SCRIPT 时对 sp_add_jobstep 的调用是:

@command=N'/FILE "<local-server-path-to.dtsx-file>" /CONNECTION "FlatFileConnection;"<unc-path-to.csv-file>" /CHECKPOINTING OFF /REPORTING E'

所以在我看来,<unc-path-to.csv-file> 以某种方式指定了 User::filePath 的值,或者可能是 SSIS 包中的 FlatFileConnection 的值。

SQL 代理作业(在 UI 中)的作业步骤属性在 General 下,然后是 Command line 选项卡,具有 Restore the original options已选中,那么 User::filePath 在哪里指定?

下面一行代码:

@command=N'/FILE "<local-server-path-to.dtsx-file>" /CONNECTION "FlatFileConnection;"<unc-path-to.csv-file>" /CHECKPOINTING OFF /REPORTING E'

是传递给用于执行 SSIS 包的 dtexec 实用程序的参数。

您可以使用以下代码行简单地传递 [User::FilePath] 值:

/SET \Package.Variables[User::FilePath].Properties[Value];"C:\File.dtsx"

整个命令将是:

@command=N'/FILE "<local-server-path-to.dtsx-file>" /CONNECTION "FlatFileConnection;"<unc-path-to.csv-file>" /CHECKPOINTING OFF /REPORTING E /SET \Package.Variables[User::FilePath].Properties[Value];"C:\File.dtsx"'

参考dtexec Utility documentation:

/Set Overrides the configuration of a variable, property, container, log provider, Foreach enumerator, or connection within a package. When this option is used, /Set changes the propertyPath argument to the value specified. Multiple /Set options can be specified.

The following is an example of executing a package and providing a new value for a variable:

dtexec /f mypackage.dtsx /set \package.variables[myvariable].Value;myvalue