如何查询SSISDB找出软件包中的错误?


15

我已经看到了这个问题 SSIS 2012-如何在T-SQL中查询当前正在运行的程序包?

它给了我以下脚本:

SELECT
    E.execution_id
,   E.folder_name
,   E.project_name
,   E.package_name
,   E.reference_id
,   E.reference_type
,   E.environment_folder_name
,   E.environment_name
,   E.project_lsn
,   E.executed_as_sid
,   E.executed_as_name
,   E.use32bitruntime
,   E.operation_type
,   E.created_time
,   E.object_type
,   E.object_id
,   E.status
,   E.start_time
,   E.end_time
,   E.caller_sid
,   E.caller_name
,   E.process_id
,   E.stopped_by_sid
,   E.stopped_by_name
,   E.dump_id
,   E.server_name
,   E.machine_name
,   E.total_physical_memory_kb
,   E.available_physical_memory_kb
,   E.total_page_file_kb
,   E.available_page_file_kb
,   E.cpu_count
,   F.folder_id
,   F.name
,   F.description
,   F.created_by_sid
,   F.created_by_name
,   F.created_time
,   P.project_id
,   P.folder_id
,   P.name
,   P.description
,   P.project_format_version
,   P.deployed_by_sid
,   P.deployed_by_name
,   P.last_deployed_time
,   P.created_time
,   P.object_version_lsn
,   P.validation_status
,   P.last_validation_time
,   PKG.package_id
,   PKG.name
,   PKG.package_guid
,   PKG.description
,   PKG.package_format_version
,   PKG.version_major
,   PKG.version_minor
,   PKG.version_build
,   PKG.version_comments
,   PKG.version_guid
,   PKG.project_id
,   PKG.entry_point
,   PKG.validation_status
,   PKG.last_validation_time
FROM
    SSISDB.catalog.executions AS E
INNER JOIN
    ssisdb.catalog.folders AS F ON F.name = E.folder_name
INNER JOIN 
    SSISDB.catalog.projects AS P ON P.folder_id = F.folder_id
                                 AND P.name = E.project_name
INNER JOIN
    SSISDB.catalog.packages AS PKG ON PKG.project_id = P.project_id
                                   AND PKG.name = E.package_name;

但这并不能满足我的要求。我正在调查软件包失败的原因,并且我需要掌握错误消息。

在哪里可以找到它?

我想使用T-SQL查询错误消息。

我在下面也有这个脚本,可以带我走近,但不完全是:

SELECT 
    q.*
FROM
    (SELECT em.*
     FROM SSISDB.catalog.event_messages em
     WHERE em.operation_id = (SELECT MAX(execution_id) 
                              FROM SSISDB.catalog.executions)
       AND event_name NOT LIKE '%Validate%') q
/* Put in whatever WHERE predicates you might like*/
--WHERE event_name = 'OnError'
WHERE package_name = 'InfoGroup Feed.dtsx'
--WHERE execution_path LIKE '%<some executable>%'
ORDER BY message_time DESC

这是我要处理的电子邮件,他们如何收到该错误消息:

欢迎提供有关如何解决SSIS错误的任何信息。

在此处输入图片说明

Answers:


22

我有一些查询。一般概念是带有信息的表是,catalog.operation_messages并且您对120(错误)类型的事件感兴趣。

根据您要构建查询的健壮性,以下两个派生表也可能会引起您的兴趣。

--- http://technet.microsoft.com/en-us/library/ff877994.aspx
-- This query translates the message_type from SSISDB.catalog.operation_messages
-- into useful text
SELECT
    D.message_type
,   D.message_desc
FROM
(
    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);


-- Where was the error message generated?
SELECT
    D.message_source_type
,   D.message_source_desc
FROM
(
    VALUES
        (10,'Entry APIs, such as T-SQL and CLR Stored procedures')
    ,   (20,'External process used to run package (ISServerExec.exe)')
    ,   (30,'Package-level objects')
    ,   (40,'Control Flow tasks')
    ,   (50,'Control Flow containers')
    ,   (60,'Data Flow task')
) D (message_source_type, message_source_desc);

我使用类似的查询来查找有关错误的信息。也许我只在乎错误是什么(查询1)。其他时候,我想知道所有失败的操作的所有活动(查询2)。通常,我很懒惰,想查看有关上一次失败的操作的所有信息(查询3并注意警告)。

-- http://msdn.microsoft.com/en-us/library/ff877994.aspx
-- Find all error messages
SELECT
    OM.operation_message_id
,   OM.operation_id
,   OM.message_time
,   OM.message_type
,   OM.message_source_type
,   OM.message
,   OM.extended_info_id
FROM
    catalog.operation_messages AS OM
WHERE
    OM.message_type = 120;

-- Generate all the messages associated to failing operations
SELECT
    OM.operation_message_id
,   OM.operation_id
,   OM.message_time
,   OM.message_type
,   OM.message_source_type
,   OM.message
,   OM.extended_info_id
FROM
    catalog.operation_messages AS OM
    INNER JOIN
    (  
        -- Find failing operations
        SELECT DISTINCT
            OM.operation_id  
        FROM
            catalog.operation_messages AS OM
        WHERE
            OM.message_type = 120
    ) D
    ON D.operation_id = OM.operation_id;

-- Find all messages associated to the last failing run
SELECT
    OM.operation_message_id
,   OM.operation_id
,   OM.message_time
,   OM.message_type
,   OM.message_source_type
,   OM.message
,   OM.extended_info_id
FROM
    catalog.operation_messages AS OM
WHERE
    OM.operation_id = 
    (  
        -- Find the last failing operation
        -- lazy assumption that biggest operation
        -- id is last. Could be incorrect if a long
        -- running process fails after a quick process
        -- has also failed
        SELECT 
            MAX(OM.operation_id)
        FROM
            catalog.operation_messages AS OM
        WHERE
            OM.message_type = 120
    );

也许我很懒惰,并且不想在失败的情况下查找此信息,就像您的团队似乎已经做了一样。我有一个按需运行的SQL Agent作业,并且有一些运行SSIS包的作业,这些作业设置为在发生故障时运行该作业。

DECLARE
    @profile_name sysname = 'SQLAdmins'
,   @recipients varchar(max) = 'billinkc@kfc.com'
,   @copy_recipients varchar(max) = NULL
,   @blind_copy_recipients varchar(max) = NULL
,   @subject nvarchar(255) = 'failed package test'
,   @body nvarchar(max) = 'Stuff has failed, fix please'
,   @body_format varchar(20) = NULL
,   @importance varchar(6) = 'NORMAL'
,   @sensitivity varchar(12) = 'NORMAL'
,   @file_attachments nvarchar(max) = NULL
,   @query nvarchar(max) = N'
SELECT
    O.object_name AS FailingPackageName
,   O.object_id
,   O.caller_name
,   O.server_name
,   O.operation_id
,   OM.message_time
,   EM.message_desc
,   D.message_source_desc
,   OM.message
FROM
    SSISDB.catalog.operation_messages AS OM
    INNER JOIN
        SSISDB.catalog.operations AS O
        ON O.operation_id = OM.operation_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'')
    ) EM (message_type, message_desc)
        ON EM.message_type = OM.message_type
    INNER JOIN
    (
        VALUES
            (10,''Entry APIs, such as T-SQL and CLR Stored procedures'')
        ,   (20,''External process used to run package (ISServerExec.exe)'')
        ,   (30,''Package-level objects'')
        ,   (40,''Control Flow tasks'')
        ,   (50,''Control Flow containers'')
        ,   (60,''Data Flow task'')
    ) D (message_source_type, message_source_desc)
        ON D.message_source_type = OM.message_source_type
WHERE
    OM.operation_id = 
    (  
        SELECT 
            MAX(OM.operation_id)
        FROM
            SSISDB.catalog.operation_messages AS OM
        WHERE
            OM.message_type = 120
    )
    AND OM.message_type IN (120, 130);
'
,   @execute_query_database sysname = NULL
,   @attach_query_result_as_file bit = 0
,   @query_attachment_filename nvarchar(260) = NULL
,   @query_result_header bit = 1
,   @query_result_width int = 256
,   @query_result_separator char(1) = char(13)
,   @exclude_query_output bit  = 0
,   @append_query_error bit = 0
,   @query_no_truncate bit = 0
,   @query_result_no_padding bit = 0
,   @mailitem_id int = NULL
,   @from_address varchar(max) = NULL
,   @reply_to varchar(max) = NULL;

-- Send email about the failure    
EXECUTE msdb.dbo.sp_send_dbmail
    @profile_name 
,   @recipients
,   @copy_recipients
,   @blind_copy_recipients
,   @subject
,   @body
,   @body_format
,   @importance
,   @sensitivity
,   @file_attachments
,   @query
,   @execute_query_database
,   @attach_query_result_as_file
,   @query_attachment_filename
,   @query_result_header
,   @query_result_width
,   @query_result_separator
,   @exclude_query_output
,   @append_query_error
,   @query_no_truncate
,   @query_result_no_padding
,   @mailitem_id OUTPUT
,   @from_address
,   @reply_to;

随意调整


8

您可以使用:

SELECT      OPR.object_name
            , MSG.message_time
            , MSG.message
FROM        catalog.operation_messages  AS MSG
INNER JOIN  catalog.operations          AS OPR
    ON      OPR.operation_id            = MSG.operation_id
WHERE       MSG.message_type            = 120

这只会给您来自SSIS包执行的错误消息。


1
做到这一点MSG.message_type IN (120, 130)
AmDB

1
@AmDB:问题是关于错误,而不是警告。如果您也想要警告,也可以添加message_type 130。
彼得·埃尔辛加

4

这是我创建的一个查询,用于从SSISDB中查找作业错误消息:

DECLARE @DATE DATE = GETDATE() - 7 -- This is to restrict the data for last 7 days, used in ON condition 

SELECT O.Operation_Id -- Not much of use 
,E.Folder_Name AS Project_Name 
,E.Project_name AS SSIS_Project_Name 
,EM.Package_Name 
,CONVERT(DATETIME, O.start_time) AS Start_Time 
,CONVERT(DATETIME, O.end_time) AS End_Time 
,OM.message as [Error_Message] 
,EM.Event_Name 
,EM.Message_Source_Name AS Component_Name 
,EM.Subcomponent_Name AS Sub_Component_Name 
,E.Environment_Name 
,CASE E.Use32BitRunTime 
WHEN 1 
THEN 'Yes' 
ELSE 'NO' 
END Use32BitRunTime 
,EM.Package_Path 
,E.Executed_as_name AS Executed_By 

FROM [SSISDB].[internal].[operations] AS O 
INNER JOIN [SSISDB].[internal].[event_messages] AS EM 
ON o.start_time >= @date -- Restrict data by date 
AND EM.operation_id = O.operation_id 

-- Edit: I change the alias from OMs to OM here:
INNER JOIN [SSISDB].[internal].[operation_messages] AS OM
ON EM.operation_id = OM.operation_id 

INNER JOIN [SSISDB].[internal].[executions] AS E 
ON OM.Operation_id = E.EXECUTION_ID 

WHERE OM.Message_Type = 120 -- 120 means Error 
AND EM.event_name = 'OnError' 
-- This is something i'm not sure right now but SSIS.Pipeline just adding duplicates so I'm removing it. 
AND ISNULL(EM.subcomponent_name, '') <> 'SSIS.Pipeline' 
ORDER BY EM.operation_id DESC 

有关详细说明,请:如何查询SSISDB以找出软件包中的错误?


1

如果您真的想知道失败的原因,请通过软件包检查一些事情以及如何进行故障排除以确保它不是连接或身份验证问题。

查看script task出现在之前的,FTP task然后更改FTP连接的属性。这应该包括FTP server URL (or IP address)TCP port numberFTP服务器侦听的usernamepassword

确保正确设置了这些连接字符串属性中的所有FTP属性,并从命令行或FTP客户端工具进行测试,以确保您在那里有价值的内容也都允许通过该方法进行连接,以确保它不是密码或错误的值问题您正在连接的内容。


问题中没有提到脚本或FTP任务。
Nick.McDermaid

@ Nick.McDermaid嗯...。实际上,该问题的最下方屏幕截图中特别显示了该问题,如果您将其完全查看的话,也会看到该问题。他收到的电子邮件似乎表明作业失败的原因是FTP问题。下次当您决定基于误解而对某事投反对票时,请确保在开始检查人们的内容之前,您已彻底阅读了完整的问题及其内容。
Pimp Juice IT

大声笑那是不必要的。没错,它在最后的屏幕快照中提到了FTP。但是屏幕截图只是给我的示例电子邮件。如果您重新阅读该问题,则不是解决FTP问题。这是关于搜索SSIS日志并发送电子邮件的。绝对没有关于“在FTP任务之前出现的脚本任务”的信息。从我的角度来看,这里真正的问题是关于日志记录和警报。
Nick.McDermaid

@ Nick.McDermaid对我来说,电子邮件屏幕截图看起来像是已经有人将其范围缩小到与FTP身份验证问题有关,即使在相应地利用FTP协议的SSIS作业中使用了FTP功能。我只是说要解决FTP身份验证问题,只需确认SSIS作业中的FTP凭据信息可以与SSIS作业之外的其他FTP连接方法一起使用,以确保例如使用的用户名和密码不允许访问。
Pimp Juice IT

哈,“ 像电子邮件示例一样 ……”认真地说,您是喜剧演员。...这是整个问题的驱动因素。我认为您是完全错误的,仅此而已!!我试图通过消除过程来帮助解决101 FTP身份验证问题。也许太基础和太标准了,但是根据我的解释和我提供的菜鸟答案的时间戳,这就是可能的有趣之处。如果我错了,那就冷静点;至少我可以承认并从中学习。哈哈
Pimp Juice IT
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.