Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

changing Agent jobs notification via msdb? Expand / Collapse
Author
Message
Posted Thursday, August 30, 2012 4:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 25, 2014 4:29 AM
Points: 119, Visits: 451
Hi all,

Id like to make sure all my agent jobs update the event log if they error.

If i go to the GUI and change the notification area and script it i get:

USE [msdb]
GO
EXEC msdb.dbo.sp_update_job @job_id=N'7be0b2e1-4404-4fb0-9b93-94a82f31ac5a',
@notify_level_eventlog=2,
@notify_level_email=2,
@notify_level_netsend=2,
@notify_level_page=2
GO
EXEC msdb.dbo.sp_attach_schedule @job_id=N'7be0b2e1-4404-4fb0-9b93-94a82f31ac5a',@schedule_id=8
GO


So i thought i would have to do a cursor to loop though my agent jobs in msdb.

looking at the msdb tables.. to find which jobs need to enabled and which i dont.. I decided to go with the SET approach and decided to try a much easier route of

UPDATE msdb..sysjobs
SET notify_level_eventlog = 2
WHERE notify_level_eventlog = 0

I didnt think you could update system tables.. but this worked.. and looking though my agent jobs in the GUI, they are all now ticked for event log..

Have a done something quite silly and other things needed to be changed for this to work properly.. Or have i found a much simpler solution!



Post #1352092
Posted Friday, August 31, 2012 11:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:06 PM
Points: 7,125, Visits: 12,720
n00bDBA (8/30/2012)
Have a done something quite silly and other things needed to be changed for this to work properly.. Or have i found a much simpler solution!

I don't know? Did you?

EXEC msdb.sys.sp_helptext 
@objname = N'dbo.sp_update_job';

I would not get into the habit of updating the tables in msdb directly. Here is a simpler way for you to produce the desired result next time you need to do something like this without using a cursor:

USE msdb;
DECLARE @sql NVARCHAR(MAX);
SET @sql = N'';

SELECT @sql = @sql + 'EXEC msdb.dbo.sp_update_job @job_name=N''' + name + ''',
@notify_level_eventlog=2,
@notify_level_email=2,
@notify_level_netsend=2,
@notify_level_page=2;
'
FROM msdb.dbo.sysjobs;

PRINT @sql; -- << output may be truncated but EXEC will execute complete content of variable

-- uncomment to exec
--EXEC(@sql);



__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1353009
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse