我想自动检查已部署的软件包是否存在任何元数据问题,例如,如果列数据长度在运行之前从varchar(20)增加到varchar(60)。午夜我在包装里遇到了一个错误,我希望能早点抓住它。
我已经尝试了[SSISDB].[catalog].[validate_package]
和catalog.validate_project
但奇怪的是他们不似乎抓住了这个特定的错误。但是,如果我打开Visual Studio,则错误会立即显示在数据流组件中而不运行包。
是否有任何方法可以验证包的元数据更改?
编辑:添加个人信息。这是一个Oracle Source数据库,所以我使用的是Attunity Oracle Source Connector。我在数据流任务上将DelayValidation设置为False,在Source组件上将ValidateExternalMetadata设置为True。
答案 0 :(得分:4)
如果您右键单击该包并选择后面的验证,则如您所识别的那样,将执行SSISDB.catalog.validate_package
过程。
它做的事情并记录到SSISDB.catalog.operation_messages
您要做的是查找message_type为110(警告)或120(错误)的消息
我创建了下表。
CREATE TABLE dbo.so_37034528
(
Col1 int
, Col2 int
, Col3 varchar(20)
, Col4 bigint
);
一个简单的SSIS包,它选择所有列并路由到行计数组件。
biml是
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection Name="tempdb" ConnectionString="Data Source=localhost\dev2014;Initial Catalog=tempdb;Provider=SQLNCLI11.0;Integrated Security=SSPI;"/>
</Connections>
<Packages>
<Package Name="so_37034528">
<Variables>
<Variable DataType="Int32" Name="RowCount">0</Variable>
</Variables>
<Tasks>
<Dataflow Name="string">
<Transformations>
<OleDbSource ConnectionName="tempdb" Name="OLESRC GetData">
<DirectInput>SELECT * FROM dbo.so_37034528;</DirectInput>
</OleDbSource>
<RowCount Name="RC Original Rows" VariableName="User.RowCount" />
</Transformations>
</Dataflow>
</Tasks>
</Package>
</Packages>
</Biml>
我将其部署到我的服务器并运行以下查询
DECLARE @validation_id bigint;
EXECUTE SSISDB.catalog.validate_package
@package_name = N'so_37034528.dtsx'
, @validation_id = @validation_id OUTPUT
, @folder_name = N'so'
, @project_name = N'so'
, @use32bitruntime = False
, @environment_scope = A
, @reference_id = NULL;
SELECT
@validation_id;
-- Wait some finite amount of time for validation
WAITFOR DELAY '00:00:20';
SELECT
D.message_desc
, OM.message
FROM
SSISDB.catalog.validations AS V
INNER JOIN
SSISDB.catalog.operation_messages AS OM
ON OM.operation_id = V.validation_id
INNER JOIN
(
VALUES
(-1,'Unknown')
, (120,'Error')
, (110,'Warning')
, (70,'Information')
, (10,'Pre-validate')
, (20,'Post-validate')
, (30,'Pre-execute')
, (40,'Post-execute')
, (60,'Progress')
, (50,'StatusChange')
, (100,'QueryCancel')
, (130,'TaskFailed')
, (90,'Diagnostic')
, (200,'Custom')
, (140,'DiagnosticEx Whenever an Execute Package task executes a child package, it logs this event. The event message consists of the parameter values passed to child packages. The value of the message column for DiagnosticEx is XML text.')
, (400,'NonDiagnostic')
, (80,'VariableValueChanged')
) D (message_type, message_desc)
ON D.message_type = OM.message_type
WHERE
V.validation_id = @validation_id
ORDER BY
V.validation_id;
我的结果看起来像
Information The validate operation has started.
Pre-validate so_37034528:Validation has started.
Pre-validate string:Validation has started.
Information string:Information: Validation phase is beginning.
Post-validate string:Validation is complete.
Post-validate so_37034528:Validation is complete.
Information The validate operation has completed.
看到我没有警告,我在对表格进行更改时重复了操作。首先,我扩展了一个专栏
ALTER TABLE dbo.so_37034528
ALTER COLUMN Col3 varchar(80);
这导致了警告
Warning string:Warning: Truncation may occur due to retrieving data from database column "Col3" with a length of 80 to data flow column "Col3" with a length of 20.
Warning string:Warning: The external columns for OLESRC GetData are out of synchronization with the data source columns. The external column "Col3" needs to be updated.
我重置了我的列长度,这次删了一列
ALTER TABLE dbo.so_37034528
ALTER COLUMN Col3 varchar(20);
ALTER TABLE dbo.so_37034528
DROP COLUMN Col4;
现在我有以下输出
Warning string:Warning: The external columns for OLESRC GetData are out of synchronization with the data source columns. The OLESRC GetData.Outputs[Output].ExternalColumns[Col4] needs to be removed from the external columns.
Error string:Error: "OLESRC GetData" failed validation and returned validation status "VS_NEEDSNEWMETADATA".
Error string:Error: One or more component failed validation.
Error string:Error: There were errors during task validation.