Export (0) Print
Expand All
Expand Minimize

ReportingService2005.CancelJob Method

Cancels the execution of a job.

Namespace:  ReportService2005
Assembly:  ReportService2005 (in ReportService2005.dll)

[SoapHeaderAttribute("ServerInfoHeaderValue", Direction = SoapHeaderDirection.Out)]
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices/CancelJob", RequestNamespace = "http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
	ResponseNamespace = "http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
	Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public bool CancelJob(
	string JobID
)

Parameters

JobID
Type: System.String
The ID of the job that you want to cancel. You can obtain the job ID from the JobID property in a Job() object.

Return Value

Type: System.Boolean
A Boolean value. A value of true is returned if the job was successfully cancelled.

An error is returned if the job ID passed in the JobID parameter is not found. If you call this method using the ID of a job that has already been cancelled, the report server ignores the operation.

Use the ListJobs method to obtain a list of jobs that are current running on the report server.

To compile this code example, you must reference the Reporting Services WSDL and import certain namespaces. For more information, see Compiling and Running Code Examples. The following code example is a console application that enables users to cancel all running jobs on a given report server:

using System;
using System.Web.Services.Protocols;

class Sample
{
   public static void Main()
   {
      ReportingService rs = new ReportingService2005();
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

      Job[] jobs = null;

      // Return a list of current jobs.
      try
      {
         jobs = rs.ListJobs();

         // Provides a prompt to cancel current jobs.
         if (ListRunningJobs(jobs))
         {
            Console.Write("Do you want to cancel these jobs (Y/N)?");
            int input = Console.Read();
            if (Char.ToLower((char)input)== 'y') 
            {
               CancelRunningJobs(jobs, rs);
            }
         }
      }
      catch (SoapException e)
      {
         Console.WriteLine(e.Detail.InnerXml.ToString());
      }
   }

   // Method to send a list of current jobs and their properties
   // to standard output.
   public static bool ListRunningJobs(Job[] jobs)
   {   
      int runningJobCount = 0;
      Console.WriteLine("Current Jobs");
      Console.WriteLine("================================" + Environment.NewLine);
      foreach (Job job in jobs)
      {
         if (job.Status == JobStatusEnum.Running || 
               job.Status == JobStatusEnum.New)
         {   
            Console.WriteLine("--------------------------------");
            Console.WriteLine("JobID: {0}", job.JobID);
            Console.WriteLine("--------------------------------");
            Console.WriteLine("Action: {0}", job.Action);
            Console.WriteLine("Description: {0}", job.Description);
            Console.WriteLine("Machine: {0}", job.Machine);
            Console.WriteLine("Name: {0}", job.Name);
            Console.WriteLine("Path: {0}", job.Path);
            Console.WriteLine("StartDateTime: {0}", job.StartDateTime);
            Console.WriteLine("Status: {0}", job.Status);
            Console.WriteLine("Type: {0}", job.Type);
            Console.WriteLine("User: {0}" + Environment.NewLine, job.User);
            runningJobCount++;
         }
      }
      Console.Write("There are {0} running jobs. ", runningJobCount);
      if (runningJobCount > 0)
         return true;
      else
         return false;
   }

   public static void CancelRunningJobs(Job[] jobs, ReportingService rs)
   {   
      try
      {
         foreach (Job job in jobs)
         {
            if (job.Status == JobStatusEnum.Running || 
               job.Status == JobStatusEnum.New)
            {   
               rs.CancelJob(job.JobID);
            }
         }
         Console.WriteLine("All jobs successfully canceled.");
      }
      catch (SoapException e)
      {
         Console.WriteLine(e.Detail.InnerXml.ToString());
      }
   }
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft