您的位置:首页 > 数据库

在Sql Server Intergration Service中设置Catalog下所部署所有项目的参数值

2017-12-26 09:30 627 查看
在Sql Server 2012开始,微软给SSIS添加了Project Model这种新的项目类型,与之对应的是在Sql Server数据库引擎中引入了Intergration Services Catalog这种新的部署方式。

当你在Sql Server中启用Intergration Service Catalog后,就会在Intergration Services Catalog下多出一个系统文件夹叫SSISDB,如下图所示我们已经发布了一个SSIS项目SSIS_LOG_TESTING到子文件夹Demo_Project_Folder下:



而在数据库中,我们也可以看到Sql Server自动生成了一个名叫SSISDB的数据库,该数据库就是用来存储Intergration Services Catalog下的项目数据的,请不要乱动其中的数据。



用过SSIS Project Model的开发人员应该都知道,这种新的项目类型相比老的Package Model有很多好处,其中一个好处就是可以在项目级别上定义全局参数,SSIS项目中的所有dtsx包都可以访问项目参数,如下图所示:



而当项目发布到Intergration Services Catalog后,也可以在Intergration Services Catalog上直接修改这些项目参数的值:





但是随之而来的问题是,随着在Intergration Services Catalog部署的SSIS项目越来越多,有没有什么办法能过统一管理这些SSIS项目的参数呢?因为Project Model的项目参数有个很大的缺点,那就是没有办法将其值存储在数据库中,而老的Pakacge Model是可以将SSIS项目中Configuration中的值存储在数据库表中的。所以导致了Project Model的项目参数没法集中管理,设想一下你的Intergration Services Catalog下如果有100个SSIS项目,假如这100项目都有一个同名的项目参数叫UserName,你现在想更改这100个项目的UserName项目参数,你只有手动打开每个项目的配置去设置UserName项目参数,是一件很耗时的操作。

而Intergration Services Catalog生成的数据库SSISDB中提供了一系列视图和存储过程,可以让我们用Sql语句来操作每个SSIS项目的项目参数,如下图所示:



其中有一个视图和存储过程特别有用,这里列出来:

视图catalog.object_parameters

该视图可以返回在Intergration Services Catalog中发布所有SSIS项目的项目参数信息,官方介绍如下:

Displays the parameters for all packages and projects in the Integration Services catalog.

Column nameData typeDescription
parameter_idbigintThe unique identifier (ID) of the parameter.
project_idbigintThe unique ID of the project.
object_typesmallintThe type of parameter. The value is
20
for a project parameter and the value is
30
for a package parameter.
object_namesysnameThe name of the corresponding project or package.
parameter_namesysname(nvarchar(128))The name of the parameter.
data_typenvarchar(128)The data type of the parameter.
requiredbitWhen the value is
1
, the parameter value is required in order to start the execution. When the value is
0
, the parameter value is not required to start the execution.
sensitivebitWhen the value is
1
, the parameter value is sensitive. When the value is
0
, the parameter value is not sensitive.
descriptionnvarchar(1024)An optional description of the package.
design_default_valuesql_variantThe default value for the parameter that was assigned during the design of the project or package.
default_valuesql_variantThe default value that is currently used on the server.
value_typechar(1)Indicates the type of parameter value. This field displays
V
when parameter_value is a literal value and
R
when the value is assigned by referencing an environment variable.
value_setbitWhen the value is
1
, the parameter value has been assigned. When the value is
0
, the parameter value has not been assigned.
referenced_variable_namenvarchar(128)The name of the environment variable that is assigned to the value of the parameter. The default value is NULL.
validation_statuschar(1)Identified for informational purposes only. Not used in SQL Server 2017.
last_validation_timedatetimeoffset(7)Identified for informational purposes only. Not used in SQL Server 2017.

Permissions

To see rows in this view, you must have one of the following permissions: +

READ permission on the project

Membership to the ssis_admin database role

Membership in the sysadmin server role.

Row-level security is enforced; only rows that you have permission to view are displayed.

MSDN链接

该视图查询结果截图如下:



存储过程catalog.set_object_parameter_value

该存储过程可以设置在Intergration Services Catalog中部署SSIS项目的项目参数,官方介绍如下:

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

Syntax

catalog.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 is used by default when 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).

Return Code Value

0 (success)

Result Sets

None

Permissions

This stored procedure requires one of the following permissions:

READ and MODIFY permissions on the project

Membership to the ssis_admin database role

Membership to the sysadmin server role

Errors and Warnings

The following list describes some conditions that may cause the stored procedure to raise an error:

The parameter type is not valid

The project name is not valid

For package parameters, the package name is not valid

The value type is not valid

The user does not have the appropriate permissions

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.

MSDN链接

该存储过程的执行结果如下:

EXEC catalog.set_object_parameter_value 20,N'Demo_Project_Folder',N'SSIS_LOG_TESTING',N'ProjectVersion',N'2.0.0.0'




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐