다음은 작업에서 사용할 수있는 스크립트입니다. 현재 날짜에 실패한 작업을 찾습니다. 이 작업을 하루에 한 번 실행하면 그 날에 실패한 작업을 볼 수 있습니다. 30 분마다 실행하고 지난 한 시간 내에 실패한 작업 만 보려면 시간 변수를 추가 할 수 있습니다. 당신은 내가 당신이 sp_send_dbmail
declare @filepath nvarchar(100) --file path where results are stored as csv
declare @filename nvarchar(100) --file name where results are stored
declare @command nvarchar(4000) --dynamic sql of bcp command
declare @count int --result count
declare @emailList varchar(4000) --people to email
declare @dt int --current date in INT format
set @filepath = '"e:\somefolder\'
set @filename = 'Failures.csv"'
set @emailList = '[email protected]; [email protected]'
set @dt = (select convert(int,replace(convert(date,substring(convert(varchar,getdate()),1,11)),'-','')))
--query to get the jobs that failed and why. Looks for jobs that were executed today.
select
h.run_date,
h.run_time,
h.run_status,
j.name,
j.description,
h.message
from
msdb.dbo.sysjobhistory h
inner join
msdb.dbo.sysjobs j on j.job_id = h.job_id
where
h.run_status = 0
and h.run_date = @dt
--if there were failures then put them in a csv and email them.
set @count = @@ROWCOUNT
if (select @count) > 0
begin
set @command = 'bcp "select h.run_date, h.run_status, j.name, j.description, h.message from msdb.dbo.sysjobhistory h inner join msdb.dbo.sysjobs j on j.job_id = h.job_id where h.run_status = 0 and h.run_date = convert(int,''' + convert(varchar,@dt) + ''') " queryout '
set @command = @command + @filepath + @filename + ' -c -t, -T '----> character data, tab delimtted is default use -t, for comma ... trusted conn,server instance to connect to
exec master..xp_cmdshell @command
exec msdb.dbo.sp_send_dbmail
@profile_name = null,
@recipients = @emailList,
@body = 'Attached is the job failure results',
@body_format = 'TEXT',
@subject = 'Job Failures',
@file_attachments = 'e:\someFolder\Failures.csv'
end
가 여기에 ssisdb 카탈로그에서 메시지를 추출하기위한 샘플 쿼리의 사용을 원하기 때문에 할 수있을 것입니다 가정
xp_cmdshell
을 사용할 수 있어야합니다. 이들은 모든 작업 로그에서 찾을 수있는 것보다 훨씬 많은 정보를 제공합니다. 당신 (또는 나)은 이것을 확장하여 주어진 패키지 이름에 대한 최신 오류를 반환 할 수 있습니다. http://sqlblog.com/blogs/jamie_thomson/archive/2012/10/17/querying-the-ssis-catalog-here-sa-handy-query.aspx –@ Nice.McDermaid - 비슷한 점이 있지만 작업이 실패하자마자 생성되는 무언가가 필요합니다. 설정된 시간에 실행되고 실패한 작업에 대한 모든 정보를 얻는 예약 된 작업이 아닙니다. 즉, 작업이 실패하고 알림 이메일을 보내 자마자 그 이메일에 오류 메시지 정보가 모두 필요하거나 전체 메시지를 캡처 할 수있는 다른 이메일이 필요합니다. –
글쎄, 이미 이메일을 보내고있다. 전자 메일을 보내는 프로세스를 설명하면 무언가를 해결할 수 있는지 알 수 있습니다. SQL 에이전트 작업 단계가 실패하면 아니면 SSIS 패키지 안에 있습니까? –