Register  Login  
  February 11, 2012  
Search_Blog Minimize
Print  

Blog_Archive Minimize
Print  

Blog    
View_Blog Minimize
Apr 10

Written by: host
Saturday, April 10, 2010 9:41 AM 

As many of you know I use DotNetNuke to monitor the operation of a rather complex Material Handling Application.  Part of the monitoring includes SQL Server Jobs.  The application has several jobs that routinely generate reports and collect and summerize data at shift changes. 

We have some other tools that monitor the health of the various servers and specifically the SQL Server application.  Those other tools will page me if they discover something out of the norm.  One issue I have had in recent months is the occasional page that a SQL Server Job had failed.   A review of the Job summary revealed no such failure. What?  So, here is where DNN and a little T-SQL helped.

SQL Server maintains the SQL Job History in tables within the MSDB database. So a rather straight forward Select can provide the all job step detail.

SELECT
  j.name as JobName,
  jh.step_name as StepName,
  CONVERT(CHAR(10), CAST(STR(jh.run_date,8, 0) AS dateTIME), 111) as RunDate,
  STUFF(STUFF(RIGHT('000000' + CAST ( jh.run_time AS VARCHAR(6 ) ) ,6),5,0,':'),3,0,':') as RunTime,
  jh.run_duration as StepDuration,
  CASE jh.run_status 
    WHEN 0 THEN 'failed'
    WHEN 1 THEN 'Succeded' 
    WHEN 2 THEN 'Retry' 
    WHEN 3 THEN 'Cancelled' 
    WHEN 4 THEN 'In Progress' 
  END as ExecutionStatus,
  jh.message as MessageGenerated
FROM
  sysjobhistory jh
  inner join sysjobs j ON j.job_id = jh.job_id
ORDER BY
  j.name,
  jh.run_date,
  jh.run_time

The above query is off interest because it uses a function I had never used before -- STUFF.  I does what the name implies, stuffs character into string and optionally removes character from the same point in the original string.  

The query results is two fields defining the event time, I prefer a single field.  This presents a rather harder challenge to create a combined date time with resonable formatting.  The effort is due to the source fields in the SYSJOBHISTORY table are integers. So here is somewhat different select with only a single event time field:

SELECT 
  CONVERT(varchar, 
  CAST (
    SUBSTRING(cast(jh.run_date as varchar(8)),1,4)
    + '/' + SUBSTRING(cast(jh.run_date as varchar(8)),5,2)
    + '/' + SUBSTRING(cast(jh.run_date as varchar(8)),7,2)
    + ' '
    + CASE len(rtrim(cast(jh.run_time as varchar)))
        when 1 then
            '00:00:0' + cast(jh.run_time as varchar)
        when 2 then
            '00:00:' + cast(jh.run_time as varchar)
        when 3 then
            '00:0' + substring(cast(jh.run_time as varchar),1,1)
           + ':' + substring(cast(jh.run_time as varchar),2,2)
     when 4 then
            '00:' + substring(cast(jh.run_time as varchar),1,2)
           + ':' + substring(cast(jh.run_time as varchar),3,2)
     when 5 then
           '0' + substring(cast(jh.run_time as varchar),1,1)
           + ':' + substring(cast(jh.run_time as varchar),2,2)
           + ':' + substring(cast(jh.run_time as varchar),4,2)
        else
           substring(cast(jh.run_time as varchar),1,2)
            + ':' + substring(cast(jh.run_time as varchar),3,2)
            + ':' + substring(cast(jh.run_time as varchar),5,2) 
      END as datetime), 20) as [Run date],
  jh.run_duration as [Duraton],
  j.name as [Job Name],
  jh.message as [Message], 
  jh.run_status as [sts]
FROM
  msdb.dbo.sysjobhistory jh with (nolock)
  join msdb.dbo.sysjobs j with (nolock) on jh.Job_id = j.Job_id
ORDER BY
  [run date] desc, 

    jh.step_id

The select will report all job steps in execution order, so if you have several jobs running at the same time, the step history may be intermixed.

Please Note: I am not the original author of these selects, I found them on the web some time ago and have modified them for my needs.  Applogies to the original authors as I did not record your names.

Using SGSV (SQLGridSelectedView), I added several filters to the display

  1. A dropdown listing all the different job - so now I can narrow the select to only a specific job.  I selected the jobs using a filter select of

    select
      distinct j.name as jobname, j.Job_id as jobid
    from
      msdb.dbo.sysjobhistory jh with (nolock)
      join msdb.dbo.sysjobs j with (nolock) on jh.Job_id = j.Job_id
    Order by 
      jobname


    The filter clause is j.job_id = '[parm:jobid]'  this will add a where clause to select only one job, but there may be many one that one execution of the job reported.
     
  2. A conditional filter to display only summary steps that adds the following condition jh.step_id = 0
     
  3. A conditional filter to display only failed steps that adds the following condition jh.run_status = 0

The above make a nice addition to determine what has happen .. unfortantely I can not show you a screenshot for privcy reasons, so I leave this an exercise for the reader.

Back to the orginal reason for using DNN.  The page I received indicated that a job had failed, but I found no failed jobs -- so by executing the about and selecting only failed job-steps, I discovered I have one job-step that had failed -- the step was marked with continue as the step was not critial to the success of overall job, so the job did run to a "sucessful" conclusion, thus no failed jobs. 

So DNN was able to help me solve the mystery.  The nice part of this is I now have a repeatable select to perform whenever I encounter a failed SQL Server job.

Hope this helps,
Paul.

Tags:

5 comment(s) so far...

Re: Failure is not an option - Checking SQL Jobs

It's great to hear from you and see what you've sent up to. All of the projects look great! You make it so simple to this. Thanks

By abercrombie and fitch on   Sunday, January 29, 2012 1:36 AM

Re: Failure is not an option - Checking SQL Jobs

All of the projects look great! You make it so simple to this. Thanks

By abercrombie fitch on   Sunday, January 29, 2012 1:38 AM

Re: Chinese Footware - and the removal of...

GameCoach Factory Outlet Onlineare usuallyCoach Factoryin By Coach Outlet Online on   Thursday, February 02, 2012 1:30 AM

NFL Jerseys

Many have been influenced to put on New York Giants Jerseys. If they see someone wearing a jerseys, these people then lease the rights to use the jerseys and begin to questions such as how much you paid for it? In which you understand? There are some people that can often wearing the NFL Jerseys Cheap in the streets or in school. It is not surprising the jerseys for men are larger, the company create many. It is very good for business, and get significant gains, there are many customers buy them just because they may be less expensive. Danny Ware Jersey wholesale is the development of affordable products and souvenirs, but usually not as elegant as the real data.High quality,plus low price,it is perfect that is exactly what we need or what we have is.The design and diverse of Patrick Chung Jersey are our want to.

By NFL Jerseys on   Saturday, February 11, 2012 2:53 AM

Coach Outlet

Handbags are Louis Vuitton a great Coach Purses product to sell Chanel Handbags. They are Coach Purses Outlet Louis Vuitton 2012 a popular Louis Vuitton Louis Vuitton item. The Coach Factory Online majority of Louis Vuitton Outlet women have Louis Vuitton Outlet many purses Louis Vuitton Bags—one for Coach Purse Louis Vuitton this outfit Coach Store Online Coach Online Outlet Store and one Louis Vuitton Handbags Coach Store Online for that Coach Outlet Store Online Louis Vuitton outfit or Coach Purses Coach Outlet Online one for Coach Purse Outlet Coach Outlet Store these colors Coach Handbags Coach Outlet and another Coach Outlet Online Coach Outlet Store Online for another www.louisvuitton.com Louis Vuitton Purses color of Louis Vuitton Handbags Louis Vuitton Outlet clothing. You’ll Louis Vuitton Outlet Stores Coach Wallets want to Coach Outlet Stores Louis Vuitton Outlet get them Coach Outlet Stores Coach Outlet Online wholesale because Coach Outlet Stores Coach Purses Outlet the price Louis Vuitton USA Louis Vuitton Sale will below Coach Purse Outlet Louis Vuitton Bags. But where Coach Outlet Online Louis Vuitton Sunglasses do you Louis Vuitton Sunglasses Louis Vuitton Outlet go to Coach Outlet Online Coach Purse get them Coach Outlet Store Online Louis Vuitton Bags wholesale?
Here are Louis Vuitton Handbags Coach Bags some ideas Louis Vuitton Outlet Store Coach Factory Outlet Store for finding Louis Vuitton Outlet Coach Outlet Store a wholesaler Louis Vuitton Louis Vuitton Outlet of handbags.
Maybe Coach Outlet Chanel Bags you already Louis Vuitton Louis Vuitton Handbags sell some Coach Outlet Online Louis Vuitton Purses other women’s Louis Vuitton Outlet Louis Vuitton Outlet products. Does Authentic Louis Vuitton Louis Vuitton Bags your wholesaler Louis Vuitton Handbags Louis Vuitton Purses sell purses Louis Vuitton Louis Vuitton Purses too? Or Louis Vuitton Louis Vuitton Bags if you Louis Vuitton Bags Coach Outlet Store Online have a relationship with another retailer that sells women’s things—your contact might know a good source for handbags.

By Coach Outlet on   Saturday, February 11, 2012 4:25 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 

Blog_List Maximize
Print  

  Home | Blog | Forum | Subscriptions | Free Modules | Videos   Page generated in 0.15664 seconds.
  Copyright 2010 by TressleWorks   Terms Of Use | Privacy Statement