Execute package from TSQL
Execute package from TSQL with parameters and variables.
Last updated:
Warning: Review and test in a non-production environment before running.
CREATE procedure [dbo].[usp_ZZZ_ssisdb]
as
begin
set nocount on;
Declare @execution_id bigint -- execution id is a unique number for the specific run
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'ZZZ.dtsx', -- name of package
@execution_id=@execution_id OUTPUT, -- return value for the specific execution id
@folder_name=N'ZZ', -- the folder in the ssisdb catalog
@project_name=N'Z', -- the project name in the ssisdb catalog
@use32bitruntime=true, -- choose 32/64 bit run (32 = true, 64 = false)
@reference_id=Null, -- no reference for now
@runinscaleout=False -- no scaleout for now
DECLARE @var0 smallint = 100, -- for logging. values(0 = none, 1 = basic ... 100 = user define log
@var1 sql_variant = N'LogRowsSent', -- name of user define log
@var2 smallint = 1 -- will be used for synchronized (0 = no synchronized, 1 = synchronized)
-- set logging to user define logging
EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id, @object_type=50, @parameter_name=N'LOGGING_LEVEL', @parameter_value=@var0
-- set logging to a specific user define logging
EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id,
@object_type=50,
@parameter_name=N'CUSTOMIZED_LOGGING_LEVEL',
@parameter_value=@var1
-- set the package to run synchronized
EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id,
@object_type=50,
@parameter_name=N'SYNCHRONIZED',
@parameter_value=@var2
declare @t table(pass nvarchar(100))
declare @str nvarchar(100)
-- get the password from incrypted data for oracle user
-- The next code get the oracle password from a saved table. change it as you wish.
insert into @t EXEC [Utility].[dbo].[GetSecret] @Env = N'oracle'
select @str=pass from @t
-- set the oracle password into package parameter
EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id,
@object_type=30,
@parameter_name=N'Password',
@parameter_value=@str
-- set the value of email to a package variable
exec [SSISDB].[catalog].[set_execution_property_override_value] @execution_id = @execution_id,
@property_path = '\Package.Variables[User::email].Properties[Value]',
@property_value = 'ZZZ@ZZZ.co.il',
@sensitive = 0
-- execute the package and wait until it finish
EXEC [SSISDB].[catalog].[start_execution] @execution_id
end;