Job.EnumHistory returns wrong information about job duration using SQL Server Management Objects
I am doing some reporting on SQL Server jobs, using SQL Server Management Objects (SMO).
This is the test-job:
This is the code:
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Smo.Agent;
...
var server = new Server("TestServer");
var agent = server.JobServer;
var job = agent.Jobs["TestJob Long"];
var jhf = new JobHistoryFilter();
var tbl = job.EnumHistory(jhf);
foreach (DataRow row in tbl.Rows.Cast<DataRow>())
{
Console.WriteLine("StepId: {0} | Date: {1} | Duration: {2} | Status:{3}", row["StepId"], row["RunDate"], row["RunDuration"], (JobOutcome)row["RunStatus"]);
}
This is the output:
StepId: 0 | Date: 27-01-2011 16:23:14 | Duration: 146 | Status:Succeeded
StepId: 3 | Date: 27-01-2011 16:24:23 | Duration: 37 | Status:Succeeded
StepId: 2 | Date: 27-01-2011 16:23:50 | Duration: 33 | Status:Succeeded
StepId: 1 | Date: 27-01-2011 16:23:14 | Duration: 36 | Status:Succeeded
Rows with stepId = 0 is a "summary" step, that contains aggregate information (or at least I thought so), but this information is wrong. 37+33+36 is no开发者_如何学Ct 146 seconds, but only 106. This fits with the time displayed in SQL Server Management Studio
This is not a problem limited to one job, one server etc - I get it everywhere.
I could add up the steps to get the right time, but I feel I am missing something here - there must be an explanation, as I do not think SMO just returns wrong information.
What am I missing here?
From TechNet:
The result set column run_time represents execution time as a scaled long integer. The integer is built as a sum of the hour scaled by 10000, the minute scaled by 100, and the seconds. The value uses a 24-hour clock. For example, the time 1:03:09 P.M. is represented by the long integer value 130309.
"Hey, let's make up a new duration datatype where we mess up an integer..."
The documentation does not actually mention that this special format applies to the duration, but it fits the description, so...
精彩评论