SSISDB2:使用TSQL API 启动一个package

Package的每一次执行都是一个Execution Instance,都有一个唯一的ExecutionID;可以指定package执行时parameter的值。

1,使用 catalog.create_execution 存储过程创建一个Execution Instance

Creates an instance of execution in the Integration Services catalog.

Syntax

create_execution [ @folder_name = folder_name
     , [ @project_name = ] project_name
     , [ @package_name = ] package_name
  [  , [ @reference_id = ] reference_id ]
  [  , [ @use32bitruntime = ] use32bitruntime ]
     , [ @execution_id = ] execution_id OUTPUT

Arguments   

[ @folder_name = ] folder_name              

The name of the folder that contains the package that is to be executed. The folder_name is nvarchar(128).

[ @project_name = ] project_name              

The name of the project that contains the package that is to be executed. The project_name is nvarchar(128).

[ @package_name = ] package_name              

The name of the package that is to be executed. The package_name is nvarchar(260).

[ @reference_id = ] reference_id              

A unique identifier for an environment reference. This parameter is optional. The reference_id is bigint.

[ @use32bitruntime = ] use32bitruntime              

Indicates if the 32-bit runtime should be used to run the package on a 64-bit operating system. Use the value of 1 to execute the package with the 32-bit runtime when running on a 64-bit operating system. Use the value of 0 to execute the package with the 64-bit runtime when running on a 64-bit operating system. This parameter is optional. The Use32bitruntime is bit.

[ @execution_id = ] execution_id              

Returns the unique identifier for an instance of execution. The execution_id is bigint.

Remarks   

An execution is used to specify the parameter values that are a package uses during a single instance of package execution.

If an environment reference is specified with the reference_id parameter, the stored procedure populates the project and package parameters with literal values or referenced values from the corresponding environment variables. If environment reference is specified, default parameter values are used during package execution. To determine exactly which values are used for a particular instance of execution, use the execution_id output parameter value from this stored procedure and query the execution_parameter_values view.

Only packages that are marked as entry point packages can be specified in an execution. If a package that is not an entry point is specified, the execution fails.

2,使用 catalog.start_execution 存储过程启动一个Execution Instance

start_execution [ @execution_id = ] execution_id

Arguments

[ @execution_id = ] execution_id              

The unique identifier for the instance of execution. The execution_id is bigint.

Remarks   

An execution is used to specify the parameter values that will be used by a package during a single instance of package execution. After an instance of execution has been created, before it has been started, the corresponding project might be redeployed. In this case, the instance of execution will reference a project that is outdated. This will cause the stored procedure to fail.

3,使用catalog.set_object_parameter_value 存储过程来修改Parameter 的Server value。

Sets the value of a parameter in the Integration Services catalog. Associates the value to an environment variable or assigns a literal value that will be used by default if no other values are assigned.

set_object_parameter_value [ @object_type = ] object_type
    , [ @folder_name = ] folder_name
    , [ @project_name = ] project_name
    , [ @parameter_name = ] parameter _name
    , [ @parameter_value = ] parameter_value
 [  , [ @object_name = ] object_name ]
 [  , [ @value_type = ] value_type ]

Arguments

[ @object_type = ] object_type              

The type of parameter. Use the value 20 to indicate a project parameter or the value 30 to indicate a package parameter. The object_type is smallInt.

[ @folder_name = ] folder_name              

The name of the folder that contains the parameter. The folder_name is nvarchar(128).

[ @project_name = ] project_name              

The name of the project that contains the parameter. The project_name is nvarchar(128).

[ @parameter_name = ] parameter_name              

The name of the parameter. The parameter_name is nvarchar(128).

[ @parameter_value = ] parameter_value              

The value of the parameter. The parameter_value is sql_variant.

[ @object_name = ] object_name              

The name of the package. This argument required when the parameter is a package parameter. The object_name is nvarchar(260).

[ @value_type = ] value_type              

The type of parameter value. Use the character V to indicate that parameter_value is a literal value that will be used by default of no other values are assigned prior to execution. Use the character R to indicate that parameter_value is a referenced value and has been set to the name of an environment variable. This argument is optional, the character V is used by default. The value_type is char(1).

Remarks 

  • If no value_type is specified, a literal value for parameter_value is used by default. When a literal value is used, the value_set in the object_parameters view is set to 1. A NULL parameter value is not allowed.
  • If value_type contains the character R, which denotes a referenced value, parameter_value refers to the name of an environment variable.
  • The value 20 may be used for object_type to denote a project parameter. In this case, a value for object_name is not necessary, and any value specified for object_name is ignored. This value is used when the user wants to set a project parameter.
  • The value 30 may be used for object_type to denote a package parameter. In this case, a value for object_name is used to denote the corresponding package. If object_name is not specified, the stored procedure returns an error and terminates.

4,使用 catalog.set_execution_parameter_value 存储过程来修改Parameter的 Execution Value

Sets the value of a parameter for an instance of execution in the Integration Services catalog.

set_execution_parameter_value [ @execution_id = execution_id
    , [ @object_type = ] object_type
    , [ @parameter_name = ] parameter_name
    , [ @parameter_value = ] parameter_value

Arguments

[ @execution_id = ] execution_id


The unique identifier for the instance of execution. The execution_id is bigint.

[ @object_type = ] object_type

The type of parameter.

For the following parameters, set object_type to 50

  • LOGGING_LEVEL
  • CUSTOMIZED_LOGGING_LEVEL
  • DUMP_ON_ERROR
  • DUMP_ON_EVENT
  • DUMP_EVENT_CODE
  • CALLER_INFO
  • SYNCHRONIZED

Use the value 20 to indicate a project parameter or the value 30 to indicate a package parameter.

The object_type is smallint.

[ @parameter_name = ] parameter_name

The name of the parameter. The parameter_name is nvarchar(128).

[ @parameter_value = ] parameter_value

The value of the parameter. The parameter_value is sql_variant.

Remarks

To find out the parameter values that were used for a given execution, query the catalog.execution_parameter_values view.

5,MSDN的Example

Declare @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution]
                        @package_name=N‘Child1.dtsx‘,
                        @execution_id=@execution_id OUTPUT,
                        @folder_name=N‘TestDeply4‘,
                        @project_name=N‘Integration Services Project1‘,
                        @use32bitruntime=False,
                        @reference_id=Null
Select @execution_id

DECLARE @var0 sql_variant = N‘Child1.dtsx‘
EXEC [SSISDB].[catalog].[set_execution_parameter_value]
                        @execution_id,
                        @object_type=20,
                        @parameter_name=N‘Parameter1‘,
                        @parameter_value=@var0

DECLARE @var1 sql_variant = N‘Child2.dtsx‘
EXEC [SSISDB].[catalog].[set_execution_parameter_value]
        @execution_id,
        @object_type=20,
        @parameter_name=N‘Parameter2‘,
        @parameter_value=@var1

DECLARE @var2 smallint = 1
EXEC [SSISDB].[catalog].[set_execution_parameter_value]
        @execution_id,
        @object_type=50,
        @parameter_name=N‘LOGGING_LEVEL‘,
        @parameter_value=@var2

EXEC [SSISDB].[catalog].[start_execution] @execution_id
GO

6,示例

6.1, 查看部署到Sql server的packages,folers,projects

--查看部署到Sql Server的packages,folers,projects
select *
from [catalog].[packages]

select *
from [catalog].[folders]

select *
from [catalog].[projects]

6.2,创建一个Execution Instance

--Create Execution Instance
Declare @execution_id bigint
EXEC [catalog].[create_execution]
                        @package_name=N‘Package1.dtsx‘,
                        @execution_id=@execution_id OUTPUT,
                        @folder_name=N‘TestISProject‘,
                        @project_name=N‘TestISProject‘,
                        @use32bitruntime=False,
                        @reference_id=Null
--Select @execution_id

参数@package_name,@folder_name,@project_name 的值是从6.1查询获取的。

6.3 查看Package使用的parameter

--查看Package使用的Parameter
select *
from catalog.object_parameters op

6.4 设置Parameter的Execution Value

--set parameter new execution value
DECLARE @ParameterA sql_variant
set @ParameterA= 11

EXEC [catalog].[set_execution_parameter_value]
                        @execution_id,
                        @object_type=30,
                        @parameter_name=N‘ParameterA‘,
                        @parameter_value=@ParameterA

6.5 执行package

启动Package的一个Execution Instance

EXEC [catalog].[start_execution] @execution_id

7,catalog.start_execution的异步性

存储过程 catalog.start_execution Starts an instance of execution in the Integration Services catalog,仅仅是开始一个Execution Instance,但是并不等待Execution Instance 执行完成,存储过程 catalog.start_execution 就会返回。

Scenario1:通过轮询方式查看Execution Instance的status

Calling [catalog].[start_execution] does not wait for the SSIS package to finish executing

It should be noted that after calling [catalog].[start_execution], your script does not wait for the SSIS package to finish executing before continuing. If any subsequent script requires the SSIS package to be complete, you must pause execution with a WHILE loop, using WAITFOR, and checking the status of the execution, before allowing your script to continue.

Example:

DECLARE @ssis_execution_status BIGINT = 1;
DECLARE @ssis_execution_id bigint
set @ssis_execution_id=xxx

EXECUTE [catalog].[start_execution] @ssis_execution_id;
WHILE(@ssis_execution_status NOT IN (3,4,6,7,9))
BEGIN
--The possible values are created (1), running (2), canceled (3), failed (4), pending (5),
--ended unexpectedly (6), succeeded (7), stopping (8), and completed (9) 

--Pause for 1 second.
WAITFOR DELAY ‘00:00:01‘;

--Refresh the status.
SELECT @ssis_execution_status=[executions].[status]
FROM [catalog].[executions]
WHERE [executions].[execution_id] = @ssis_execution_id

END

Scenarion2:通过设置特殊 Parameter 的Execution Value。

package execution is async by default, but can be sync by setting a parameter

exec catalog.set_execution_parameter_value
                @execution_id,
                @object_type= 50,
                @parameter_name = N‘Synchronized‘,
                @parameter_value = 1;

Synchronized 是一个特殊的Parameter,设置Execution Value为1,那么存储过程 catalog.start_execution 将等到Package执行完成之后返回。

In order to call the package synchronously, and therefore keep the caller waiting until the package finishes, you have to set a parameter value to true.  This parameter, SYNCHRONIZED

To call it, simply call catalog.set_execution_parameter_values before calling catalog.start_execution and set the SYNCHRONIZED parameter to true (1).  Like so:

EXEC [SSISDB].[catalog].[set_execution_parameter_value]
        @execution_id,  -- execution_id from catalog.create_execution
        @object_type=50,
        @parameter_name=N‘SYNCHRONIZED‘,
        @parameter_value= 1; -- turn on synchronized execution

推荐文档:

http://www.ssistalk.com/2012/07/24/quick-tip-run-ssis-2012-packages-synchronously-and-other-execution-options/

参考文档:

https://msdn.microsoft.com/en-us/library/ff878034.aspx

https://msdn.microsoft.com/en-us/library/ff878160.aspx

https://msdn.microsoft.com/en-us/library/ff877990.aspx

https://msdn.microsoft.com/en-us/library/ff878089.aspx

时间: 2024-10-12 08:57:50

SSISDB2:使用TSQL API 启动一个package的相关文章

Win7中如何在服务中启动一个当前用户的进程——函数CreateProcessAsUser()的一次使用记录

这次工作中遇到要从服务中启动一个具有桌面UI交互的应用,这在winXP/2003中只是一个简单创建进程的问题.但在Vista 和 win7中增加了session隔离,这一操作系统的安全举措使得该任务变得复杂了一些. 一.Vista和win7的session隔离 一个用户会有一个独立的session.在Vista 和 win7中session 0被单独出来专门给服务程序用,用户则使用session 1.session 2... 这样在服务中通过CreateProcess()创建的进程启动UI应用用

Win7中如何在服务中启动一个当前用户的进程——一次CreateProcessAsUser()使用记录

这次工作中遇到要从服务中启动一个具有UI交互的桌面应用,这在winXP/2003中只是一个简单创建进程的问题.但在Vista 和 win7中增加了session隔离,这一操作系统的安全举措使得该任务变得复杂了一些. 一.Vista和win7的session隔离 一个用户会有一个独立的session.在Vista 和 win7中session 0被单独出来专门给服务程序用,用户则使用session 1.session 2... 这样在服务中通过CreateProcess()创建的进程启动UI应用用

Android学习路线(十二)Activity生命周期——启动一个Activity

先占个位置,过会儿来翻译,:p Unlike other programming paradigms in which apps are launched with a main()method, the Android system initiates code in an Activity instance by invoking specific callback methods that correspond to specific stages of its lifecycle. Th

C#启动一个外部程序(1)-WinExec

C#启动一个外部程序(1)-WinExec 调用Win32 API.1. using System.Runtime.InteropServices; 2. //        //#define SW_HIDE             0 //隐藏窗口,活动状态给令一个窗口        //#define SW_SHOWNORMAL       1 //用原来的大小和位置显示一个窗口,同时令其进入活动状态        //#define SW_NORMAL           1      

Android实现开机自启动(二)——启动一个activity

在上一篇的基础上,我们收到了广播,现在我们想做点什么..比如启动一个服务,或者启动一个activity.以activity为例,下面聊一聊具体做法. 在onReceive方法里跳转到activity即可,需要注意的是在startActivity之前要setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 或者addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);两个是一个意思. 下面给代码 1 package com.example.testr

java之如何实现调用启动一个可执行文件,exe

1 /* 2 * 运行可执行文件:.exe 3 * 当要执行一个本地机器上的可执行文件时, 4 * 可以使用java.lang包中的Runtime类,首先使用Runtime类,首先 5 * 使用Runtime类声明一个对象 6 *{ 7 * Runtime sc =Runtime.getRuntime(); 8 * sc可以调用exec(String command) 方法打开本地湖区上的可执行文件或执行一个操作. 9 * } 10 */ 11 12 13 /* 14 * 不妨举列: 15 *

Android启动一个只知道包名的应用

我们知道,要启动一个应用,就需要知道应用启动Activity的名称,可是启动Activity的ACTION参数,这样就可以通过startActivity(Intent)来启动,如: /**被启动的应用的包名为com.xx.xx,应用的入口为com.xx.xx.TestLaunchActivity**/ Intent intent = new Intent(); intent.setComponent(new ComponentName("com.xx.xx","com.xx.

Android官方入门文档[12]启动一个活动

Android官方入门文档[12]启动一个活动 Starting an Activity启动一个活动 This lesson teaches you to1.Understand the Lifecycle Callbacks2.Specify Your App's Launcher Activity3.Create a New Instance4.Destroy the Activity 这节课教你1.了解生命周期回调2.指定您的应用程序的启动活动3.创建一个新实例4.销毁活动 You sho

cinder api启动过程源码分析

1.启动cinder-api服务 当你通过cinder-api命令(如:/usr/bin/cinder-api --config-file /etc/cinder/cinder.conf)启动api服务时,执行的实际上是 cinder/cmd/api.py/main()函数, 如下: [[email protected] ~]# cat /usr/bin/cinder-api #!/usr/bin/python2 # PBR Generated from u'console_scripts' i