Issues with Microsoft.SqlServer.Smo C# Job.EnumHistory()
-
Wednesday, June 20, 2012 5:45 PM
All-
I am getting a C# Exception:
"Enumerate history failed for Job 'xxxxxxx'. "
on line:
at Microsoft.SqlServer.Management.Smo.Agent.Job.EnumHistory(JobHistoryFilter filter)
What is strange is that I am unable to consistently reproduce this error. It happens every few days on a service I'm using to monitor a SQL Server Agent Job.
Using Powershell command:
$v = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')
I have confirmed we are using Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91.
We are using Microsoft SQL Server 2008 R2.
What causes this error?
Any help is appreciated.
Thanks,
-Kevin
All Replies
-
Wednesday, June 20, 2012 11:05 PMModerator
Hello Kevin,
Can you try the following power shell script and let us know if you are seeing same issue?
Thanks
Sethu Srinivasan [MSFT]
SQL Server
-
Friday, June 22, 2012 1:29 PM
Sethu-
I ran this script successfully for the job that is throwing an exception. There was no output from the script for this job.
-Kevin
-
Wednesday, June 27, 2012 1:19 PMAny other suggestions out there?
-
Monday, July 02, 2012 1:44 PMbump
-
Saturday, July 28, 2012 9:08 PMModerator
Hello,
Have you looked at the contain of the script ? It is written in PowerShell with a call to EnumHistory. What is the value of the parameter of the EnumHistory ?
Have a nice day
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
-
Tuesday, August 14, 2012 9:01 PMModerator
Kevin, Could you please post code sample in this forum?
Thanks
Sethu Srinivasan [MSFT]
SQL Server
-
Monday, August 20, 2012 3:53 PM
Kevin, Could you please post code sample in this forum?
Thanks
Sethu Srinivasan [MSFT]
SQL Server
/// <summary> /// Get last job result of the Sql Server Monitor. /// </summary> /// <returns></returns> public IMonitorResult GetJobHistory() { const string connectionNotOpen = "Sql Server Connection is not open"; int successfulJobs = 0; int failedJobs = 0; Job job; IList<string> jobRunDescriptions = new List<string>(); //IMonitorResult monitorResult = null; if (_serverConnection.IsOpen) { string[] monitoredJobs = _sqlserverAgentMonitor.MonitorJobs.Split(','); DataTable jobHistory; foreach (string monitorJob in monitoredJobs) { // Find the job on SQLServer. job = _server.JobServer.Jobs[monitorJob.Trim()]; if (job != null) { if (!job.IsEnabled) { _thresholdResult = ThresholdType.Warning; jobRunDescriptions.Add(Msg.ErrorJobDisabled + monitorJob); failedJobs++; } else if (CheckJobRan(job)) { // Create job filter to retrieve job history. JobHistoryFilter jobHistoryFilter = new JobHistoryFilter { JobID = job.JobID, OldestFirst = false, JobName = monitorJob }; // Get job history. jobHistory = job.EnumHistory(jobHistoryFilter); jobRunDescriptions.Add(jobHistory.Rows[0]["JobName"] + ":" + jobHistory.Rows[0]["Message"] + Environment.NewLine); if (job.LastRunOutcome != CompletionResult.Succeeded) { _thresholdResult = ThresholdType.Critical; failedJobs++; } else { successfulJobs++; } } else { _thresholdResult = ThresholdType.Warning; jobRunDescriptions.Add("Job did not run at the scheduled time: " + monitorJob); failedJobs++; } } else { _thresholdResult = ThresholdType.Critical; jobRunDescriptions.Add("Job not found:" + monitorJob); failedJobs++; } } int totalJobs = failedJobs + successfulJobs; _monitorResult = new MonitorResultImpl(_sqlserverAgentMonitor, _thresholdResult, 0, Environment.NewLine + "Total Jobs: " + totalJobs + Environment.NewLine + "Failed Jobs: " + failedJobs + Environment.NewLine + "Successful Jobs: " + successfulJobs + (jobRunDescriptions.Any() ? Environment.NewLine + string.Join(Environment.NewLine, jobRunDescriptions.ToArray()) : string.Empty)); return _monitorResult; } _monitorResult = new MonitorResultImpl(_sqlserverAgentMonitor, ThresholdType.Critical, 0, connectionNotOpen); return _monitorResult; }
-
Tuesday, August 21, 2012 2:34 PM
I am definitely passing in the required job information. The code is working as expected except for on this machine.Kevin, Could you please post code sample in this forum?
Thanks
Sethu Srinivasan [MSFT]
SQL Server
-
Thursday, August 23, 2012 3:47 PMThis seems to only be happening on a few select machines. It is working as expected in most places. Everything I see though says that I am running the 10.x DLL.
-
Thursday, August 23, 2012 3:56 PMWhat about dependent DLLs? Can you verify that you are loading the correct version of Microsoft.SqlServer.SqlEnum?
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread. -
Thursday, August 23, 2012 6:33 PM
What about dependent DLLs? Can you verify that you are loading the correct version of Microsoft.SqlServer.SqlEnum?
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.Version 10.x of the above DLL is being loaded
Confirmed with: $v = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SqlEnum')
in powershell.
-
Thursday, August 23, 2012 9:03 PM
Please verify the following too and compare to what is being loaded in the machines that do work:
Microsoft.SqlServer.Management.Sdk.Sfc.dll
Also, is what you wrote in your original post all you have for the exception?
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread. -
Friday, August 24, 2012 1:32 PM
Please verify the following too and compare to what is being loaded in the machines that do work:
Microsoft.SqlServer.Management.Sdk.Sfc.dll
Also, is what you wrote in your original post all you have for the exception?
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.Monica-
I will look into this DLL too. What I have in the original post is the whole exception minus some of the stack trace.
-Kevin
-
Friday, August 24, 2012 1:53 PM
10.50.2500.0 is being used on the environment throwing this exception.Please verify the following too and compare to what is being loaded in the machines that do work:
Microsoft.SqlServer.Management.Sdk.Sfc.dll
Also, is what you wrote in your original post all you have for the exception?
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.Monica-
I will look into this DLL too. What I have in the original post is the whole exception minus some of the stack trace.
-Kevin
-
Friday, August 24, 2012 5:12 PM
If you're loading 10.00.x of Microsoft.SqlServer.Smo.dll, this might be causing the problem.
I would suggest getting the right version to run your app.
See the the answer in this link: http://social.msdn.microsoft.com/Forums/en/sqlnetfx/thread/1d2cb76b-642f-4067-9667-aacdbc142f74
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.- Proposed As Answer by Papy NormandModerator Thursday, August 30, 2012 4:54 PM
- Marked As Answer by Sethu SrinivasanMicrosoft Employee, Moderator Saturday, October 27, 2012 7:43 PM

