Skip to main content

SSIS Error Log Notification

USE msdb

GO

DECLARE

          @ToEmail VARCHAR(1000) = '',

          @CCEmail VARCHAR(1000) = '',

          @minute INT = null

 

SET NOCOUNT ON

DECLARE c4 cursor for

SELECT  id , event , computer , operator , source , sourceid ,       executionid , starttime , endtime , message  FROM sysssislog

WHERE executionid in (SELECT executionid FROM sysssislog WHERE event = 'OnError' )

and starttime > dateadd(mi, -@minute, getdate())

ORDER BY executionid, id

 

open c4

DECLARE @id INT,

              @event VARCHAR(256),

              @computer VARCHAR(256),

              @operator VARCHAR(256),

              @source VARCHAR(256),

              @sourceid uniqueidentifier,

              @executionid uniqueidentifier,

              @starttime datetime,

              @endtime datetime,

              @message VARCHAR(1024),

              @errormsg VARCHAR(4000)

 

DECLARE @startid INT,

              @cur_package VARCHAR(256),

              @endid INT,

              @pre_id INT,

              @start_time datetime,

              @end_time datetime,

              @cmd VARCHAR(8000)

 

DECLARE @subject1 VARCHAR(256)

 

SET @errormsg = ''

SET @cmd = ''

fetch next FROM c4 INTo @id , @event , @computer , @operator , @source , @sourceid , @executionid , @starttime , @endtime , @message

while @@fetch_status = 0

begin


          if @message like 'End of package execution.%'

          begin

                   SET @endid = @id

                   SET @end_time = @endtime

                  

                   SELECT @startid = id FROM sysssislog WHERE executionid = @executionid and

                                         event = 'PackageStart' and message like 'Beginning of package execution.%'

                   SELECT @start_time = starttime FROM sysssislog WHERE executionid = @executionid and

                                         event = 'PackageStart' and message like 'Beginning of package execution.%'

                   SELECT @errormsg = @errormsg + message FROM sysssislog WHERE id between @startid and

                                         @endid and executionid = @executionid

                  

                   SET @subject1 = 'SSIS Package ' + @source + ' Failed on ' + @@SERVERNAME

                  

                   SELECT @cmd = @cmd + 'SQL Instance: ' + @@SERVERNAME + CHAR(10)

                   SELECT @cmd = @cmd + 'Package Name: ' + @source + CHAR(10)

                   SELECT @cmd = @cmd + 'Job Originating Host: ' + @computer + CHAR(10)

                   SELECT @cmd = @cmd + 'Run As: ' + @operator + CHAR(10)

                   SELECT @cmd = @cmd + 'Start DT: ' + convert(VARCHAR(30),@start_time,121) + CHAR(10)

                   SELECT @cmd = @cmd + 'End DT: ' + convert(VARCHAR(30),@end_time,121) + CHAR(10)

                   SELECT @cmd = @cmd + 'Error Message: '+ CHAR(10) + @errormsg

 

                             exec  msdb.dbo.sp_send_dbmail

                             @recipients= @ToEmail,

                             @copy_recipients = @CCEmail,

                             @subject =  @subject1,

                             @body_format ='TEXT',

                             @body = @cmd

                  

          SET @errormsg = ''             

          SET @cmd = ''

          END

SET @pre_id = @id

fetch next FROM c4 INTO @id , @event , @computer , @operator , @source , @sourceid , @executionid , @starttime , @endtime , @message

END

 

close c4

deallocate c4

GO


Comments

  1. The information you shared was useful. Thank you for taking the time to organize it.

    ReplyDelete
  2. Thank you for your valuable feedback

    ReplyDelete

Post a Comment

Hi User,
Thanks for visiting My Blog and please provide your valuable feedback and subscribe for more updates. Please don't post any spam content or comments.
Thank You

Popular posts from this blog

SSRS INTERVIEW QUESTIONS

Q: What is SSRS? Ø   SSRS or SQL Server Reporting Service is a server-based report generation software systems from Microsoft and is part of Microsoft BI. Ø   It is used for preparing and delivering interactive and variety of reports. Ø   It is administered through an web based interface. Ø   Reporting services utilizes a web service interface for supporting and developing of customized reporting applications. Ø   SSRS lets you create very rich reports (Tabular/Graphical/Interactive) from various datasources with rich data visualization (Charts, Maps, sparklines) Ø   SSRS allows are reports to be exported in various formats (Excel, PDF, word etc) Q: Explain SSRS Architecture? Reporting services architecture comprises of integrated components. It is a multi-tiered, included with application, server and data layers. This architecture is scalable and modular. A single installation can be used across multiple computers. It includes the fo...

Exception deserializing the package "The process cannot access the file because it is being used by another process."

TITLE: Microsoft Visual Studio ------------------------------ Failed to start project ------------------------------ ADDITIONAL INFORMATION: Exception deserializing the package "The process cannot access the file 'E:\SSASCube\HistoricalDataLoad\HistoricalDataLoad\bin\Development\HistoricalDataLoad.ispac' because it is being used by another process.". (Microsoft.DataTransformationServices.VsIntegration) ------------------------------ The process cannot access the file 'E:\SSASCube\HistoricalDataLoad\HistoricalDataLoad\bin\Development\HistoricalDataLoad.ispac' because it is being used by another process. (mscorlib) ------------------------------ BUTTONS: OK ------------------------------ While running SSIS package i got the error “The process cannot access the file ‘*.ispac’ because it is being used by another process”. I tried to close SSDT and run it again but, I still got the same error while compiling. Then, after searching over internet, I got...

Failed to execute the package or element. Build errors were encountered

Error: TITLE: Microsoft Visual Studio ------------------------------ Failed to execute the package or element.   Build errors were encountered. For more information, see the Output window. ------------------------------ BUTTONS: OK ------------------------------   Solution: We tried to close SSDT and run it again but, we still got the same error while running SSIS package. Then, we need to follow bellow solution: Step 1: Go to Task Manager–> Details Tab. Step 2: Locate the process “ DtsDebugHost.exe “. Kill this process. There might be multiple instances of this process. Kill all of them. Step 3: Rerun SSIS package