简体   繁体   English

如何在 Calalog 中执行 SSIS package 后读取变量值?

[英]How to read variables values after execute a SSIS package in the Calalog?

I am trying to execute a SSIS package from a store procedure, and I want to get the value of a variable defined in the SSIS package. I can execute tha package but I do not know how to get the value of the variable after the executtion我正在尝试从存储过程执行 SSIS package,我想获取 SSIS package 中定义的变量的值。我可以执行 package 但我不知道如何在执行后获取变量的值

I am executing the package in this way:我正在以这种方式执行 package:

-- Create the execution object
DECLARE @execution_id BIGINT
EXEC [SSISDB].[catalog].[create_execution] 
    @package_name=N'package.dtsx'
    , @project_name=N'my_project'
    , @folder_name=N'packages'
    , @use32bitruntime=False
    , @reference_id=NULL
    , @execution_id=@execution_id OUTPUT

-- System parameters
EXEC [SSISDB].[catalog].[set_execution_parameter_value] 
    @execution_id
    , @object_type = 50                     -- System parameter
    , @parameter_name = N'SYNCHRONIZED'
    , @parameter_value = 1

DECLARE @PATH AS VARCHAR(100)
SET @PATH='c:\results\test.xlsx'

EXEC [SSISDB].[catalog].[set_execution_property_override_value] 
  @execution_id = @execution_id,
  @property_path = '\package.Variables[User::FILE_PATH].Properties[Value]',
  @property_value = @PATH,
  @sensitive = 0; 

-- Execute the package
EXEC [SSISDB].[catalog].[start_execution] @execution_id

-- Check package status, and fail script if the package failed
IF 7 <> (SELECT [status] FROM [SSISDB].[catalog].[executions] WHERE execution_id = @execution_id)
RAISERROR('The package failed. Check the SSIS catalog logs for more information', 16, 1)

My package writes a value to a variable called ID, and I need to get the value.我的 package 将一个值写入一个名为 ID 的变量,我需要获取该值。 Is there a way to do this?有没有办法做到这一点?

If it's a thing I need to work with regularly, I'd create a custom table.如果这是我需要经常处理的事情,我会创建一个自定义表格。 Something like this像这样的东西

CREATE TABLE dbo.PackageRunLog
(
    PackageControlSK int IDENTITY(1, 1) NOT NULL 
,   PackageName varchar(100) NOT NULL
,   PackageID uniqueidentifier NOT NULL
,   ExecutionID bigint NULL
,   MyCustomVariable int
};

As the final step of your package, have an Execute SQL Task that makes an insert into the table.作为 package 的最后一步,有一个 Execute SQL Task 可以插入到表中。

INSERT INTO dbo.PackageRunLog VALUES (?, ?, ?, ?);

In the Parameter section, use the following SSIS variables在参数部分,使用以下 SSIS 个变量

  • System::PackageName系统::包名称
  • System::PackageID系统::包ID
  • System::ServerExecutionID系统::服务器执行ID
  • User::MyVariable用户::我的变量

The first two record the package friendly name and the second is the internal guid associated to your package. This can be helpful in case someone has a generic named package LoadData which matches your package LoadData.前两个记录 package 友好名称,第二个是与您的 package 关联的内部 guid。如果有人有一个名为 package LoadData 的通用名称与您的 package LoadData 匹配,这将很有帮助。 Or if package names change, whatever.或者如果 package 名称发生变化,无论如何。

The magic is System::ServerExecutionID This value is the execution_id/operation_id recorded in SSISDB.catalog.operations, catalog.operation_messages etc神奇的是System::ServerExecutionID这个值就是SSISDB.catalog.operations,catalog.operation_messages等记录的execution_id/operation_id

Finally, we map our SSIS variable MyVariable into it.最后我们把map我们的SSIS变量MyVariable放进去。

My actual run log has start/stop dates, insert/update/delete counts but that's the general pattern.我的实际运行日志有开始/停止日期、插入/更新/删除计数,但这是一般模式。

My Lazy approach would be to fire an information event in a script task and then parse the resulting value out of ssisdb.catalog.operation_messages我的惰性方法是在脚本任务中触发信息事件,然后从 ssisdb.catalog.operation_messages 中解析结果值

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

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