Schedule Windows Service or Console App using Microsoft SQL JOB

By: Nirav
Updated: February 14, 2017 | Technology: Asp.Net, Asp.Net MVC
Schedule Windows Service or Console App using Microsoft SQL JOB

What is a SQL JOB?

Let me explain, a JOB is a specified series of actions that SQL server agent performs. Use JOBs to define an administrative task and it can be run one or many as times and monitored either success or failure. A SQL JOB can run on one local or multiple remote servers. That’s it.

NOW! Suppose we want to run windows application on a specific time interval.

Especially, There is one way to create an job scheduling using Quartz and here I am going to introduce one another way which is not commonly in use using SQL Jobs.

Most Noteworthy, Here I am going to introduce one other way which is not well known among some .Net developers.This is by creating schedule JOB in Microsoft SQL Server.

Here I am going to explain you some steps for the run application using jobs. Follow the steps.

  1. Publish your windows application or console application.
    SQL JOB
  2. Open Microsoft SQL server management studio and navigate to SQL Server Agent and find Job.
  3. Right click on Job Folder and click on New Job and fill general details.
    SQL JOB
  4. Now on left navigation on new job window click on steps and click on New button at the bottom.
    SQL JOB
  5. Above steps will open new window “New Job Step”, write steps name and select “Type: Operating system (CmdExec)”.
  6. Now in command window copy the full path of the ex, you would like to execute and save this step. All above 1-6 steps are responsible for defining which job to be executed still, we have to define at what time/interval.
  7. Not to make it schedule click on “Schedules” in New Job window under Steps and click on New button.
    SQL JOB
  8. After clicking a new button it will open New Job Schedule where SQL server is full with a lot of option on which frequency you would like to run your application.

That’s all you have to follow only 8 easy steps and your schedule will start working with SQL server.

There is one advantage of this kind of approach, NET server developer can easily call this job from stored procedure or code itself by executing the command “exec msdb.dbo.sp_start_job N’youjobname’”

I hope that this blog will help you. If you like my blog then you can share on social with your friends.