Job.EnumHistory 使用 SQL Server 管理对象返回有关作业持续时间的错误信息
我正在使用 SQL Server 管理对象 (SMO) 对 SQL Server 作业进行一些报告。
这是测试作业:
这是代码:
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"]);
}
这是输出:
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 是一个“摘要”步骤,包含聚合信息(或者至少我是这么认为的),但此信息是错误的。 37+33+36 不是 146 秒,而是 106 秒。这与 SQL Server Management Studio 中显示的时间相符
这不是一个仅限于一项作业、一台服务器等的问题 - 我到处都遇到这个问题。
我可以添加步骤以获得正确的时间,但我觉得我在这里遗漏了一些东西 - 必须有一个解释,因为我不认为 SMO 只是返回错误的信息。
我在这里缺少什么?
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 not 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 TechNet:
“嘿,让我们创建一个新的持续时间数据类型,其中我们弄乱了一个整数......”
文档实际上并没有提到这种特殊格式适用于持续时间,但符合描述,所以...
From TechNet:
"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...