标签:
Environment 是ETL执行时使用的Parameters的集合,可以为一个Project引用不同的Environment variables,从而改变ETL执行的属性。
查看Environments,如图
1,Create Environment
EXEC [SSISDB].[catalog].[create_environment] @environment_name=N‘WeekDay‘, @environment_description=N‘‘, @folder_name=N‘Demo‘ GO
2,在环境中创建变量
DECLARE @var sql_variant = N‘"first"‘ EXEC [SSISDB].[catalog].[create_environment_variable] @variable_name=N‘VarEnv‘, @sensitive=False, @description=N‘‘, @environment_name=N‘WeekDay‘, @folder_name=N‘Demo‘, @value=@var, @data_type=N‘String‘ GO
3,将项目配置为引用Environment
右击ProjectName,点击Configure,在Parameters Tab中查看project的Parameters。
点击References Tab,设置project 引用Environment。
Declare @reference_id bigint EXEC [SSISDB].[catalog].[create_environment_reference] @environment_name=N‘WeekDay‘, @environment_folder_name=N‘Demo‘, @reference_id=@reference_id OUTPUT, @project_name=N‘ISStudy‘, @folder_name=N‘Demo‘, @reference_type=A Select @reference_id GO
回到Parameters Tab,点击value column后面的ellipsis 设置project Variables引用 Environment variables。
EXEC [SSISDB].[catalog].[set_object_parameter_value] @object_type=20, @parameter_name=N‘VarEnv‘, @object_name=N‘ISStudy‘, @folder_name=N‘Demo‘, @project_name=N‘ISStudy‘, @value_type=R, @parameter_value=N‘VarEnv‘ GO
参数 @value_type ,参数值=R,表明参数值是一个引用值,且正在使用一个Environment Variable;参数值=V,表示参数是一个文本值
通过 catalog.environment_references 查看Reference
reference_type: Indicates whether the environment can be located in the same folder as the project (relative reference) or in a different folder (absolute reference). When the value is R, the environment is located by using a relative reference. When the value is A, the environment is located by using an absolute reference.
A project can have relative or absolute environment references. Relative references refer to the environment by name and require that it resides in the same folder as the project. Absolute references refer to the environment by name and folder, and may refer to environments that reside in a different folder than the project. A project can reference multiple environments.
对于Demo这个folder来说,LocalFolder下的Environment 是Relative Environment,在Demo下的Environment 是absolute Environment。
参考MSDN:catalog.environment_references (SSISDB Database)
4,执行Package,引用Environment Variable,在 [catalog].[create_execution] 的参数 @reference_id中设置引用对象
Declare @execution_id bigint EXEC [SSISDB].[catalog].[create_execution] @package_name=N‘Package.dtsx‘, @execution_id=@execution_id OUTPUT, @folder_name=N‘Demo‘, @project_name=N‘ISStudy‘, @use32bitruntime=False, @reference_id=1 Select @execution_id DECLARE @var0 smallint = 1 EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id, @object_type=50, @parameter_name=N‘LOGGING_LEVEL‘, @parameter_value=@var0 EXEC [SSISDB].[catalog].[start_execution] @execution_id GO
标签:
原文地址:http://www.cnblogs.com/ljhdo/p/4954351.html