15

I have seen this question SSIS 2012 - How to Query Currently Running Packages in T-SQL?

It gives me the following script:

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;

But it does not answer my quest. I am investigating the reasons why packages fail and I need to get hold of the error messages.

Where can I find it?

I would like to use T-SQL to query for the error message.

I have also this script below, that takes me near, but not quite:

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

This is the email I would like to tackle, how did they get to that error message:

Any information as how to troubleshoot SSIS errors is welcome.

enter image description here

22

I have a handful of queries I use. The general concepts are that the table with the information is catalog.operation_messages and you are interested in events with a 120 (error) type.

Depending on how robust of a query you want to build out, the following two derived tables might also be of interest.

--- 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);

I use queries like this to find information about the errors. Maybe I only care about what the errors were (query 1). Other times, I want to know all the activities of all the operations that failed (query 2). Generally, I'm lazy and want to see all the information about the last failing operation (query 3 and note the caveat).

-- 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
    );

Perhaps I'm lazy and don't want to go look this information up in the event of a failure, much as your team appears to have done. I have a SQL Agent job that runs on demand and I have jobs that run SSIS packages set to run that job in the event of failure.

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;

Adjust as you like

8

You can use:

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

This will give you only the error messages from SSIS package executions.

  • 1
    Make it MSG.message_type IN (120, 130) – AmDB May 10 '16 at 13:31
  • 1
    @AmDB: The question is about errors, not warnings. If you want warnings too, one could add message_type 130 too. – Peter Elzinga May 15 '16 at 15:38
4

Here is one query I created to find the job error message from the 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 

For the detail explanation please the: how to query SSISDB to find out the errors in the packages?

1

If you really want to know why it's failing, here are some things to check with the package and how to troubleshoot to ensure it's not a connection or authentication issue.

Look at the script task that appears just before the FTP task and change the properties for the FTP connection. This should include the FTP server URL (or IP address), the TCP port number the FTP server listens on, the username, and password.

Ensure that all FTP attributes in these connection string properties are set correctly, and test from command line or an FTP client tool to ensure that whatever you have value wise in there also allows connection via that method to ensure it's not a password or incorrect value issue of what you're connecting to.

  • There is no script or FTP task mentioned in the question. – Nick.McDermaid Aug 14 '18 at 4:14
  • @Nick.McDermaid Uh.... actually that specifically is shown in the bottom most screen shot of the question if you look it over completely you will see that as well. It looks like the email he got was indicating the reason the job was failing was due to the FTP issue. Next time you decide to down vote something based on your misconceptions, be sure you thoroughly read the entirely question and its contents before you start scrutinizing peoples content. – Pimp Juice IT Aug 14 '18 at 12:41
  • LOL that was pretty unnecessary. You are right it mentions FTP in the screenshot at the end. But the screenshot just looks like an an example email to me. If you reread the question, it's not about solving an FTP problem. It's about searching the SSIS log and sending emails. There is definitely nothing about "the script task that appears just before the FTP task" there. From my perspective, the real question here is about logging and alerting. – Nick.McDermaid Aug 14 '18 at 22:46
  • @Nick.McDermaid To me the email screen shot looked like someone already narrowed it down to being related to an FTP authentication issue even though it is FTP functionality being used within an SSIS job utilizing the FTP protocol accordingly. I was just saying to troubleshoot the FTP authentication issue, simply confirm that the FTP credential information within an SSIS job works with another FTP connection method outside of the SSIS job to ensure the username and password you are using for example doesn't allow access. – Pimp Juice IT Aug 14 '18 at 23:01
  • Ha, "like an example email".... seriously, you are a comedian.... that's the driving factor of the entire question. I think you are plain wrong and that's just it instead!! I was trying to help easily troubleshoot 101 FTP authentication issue via process of elimination. Maybe too basic and standard but as per my interpretation and the timestamp on the rookie answer I provided, that is what that was about as funny as it may be. If I'm wrong, cool; at least I can admit and learn from it. LOL – Pimp Juice IT Aug 15 '18 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.