Question

I am working on Visual Studio 2012 with Update 2 + SQL Server Data Tools and I am able work on the SQL Server Database Projects.

How do I create/add new SQL Agent JOB into this database project? Because if I click Add - New Item... I don't see anything for Job.

I know Jobs are related to SQL Server and the Database Project is related to a SQL Database. But I was wondering how do manage the SQL Jobs?

Thanks,
Prabhat

Was it helpful?

Solution

Jobs aren't supported natively. It might be possible to add these from the post-deployment script, although it's not something I've tried.

OTHER TIPS

Creating server agent objects are not supported by visual studio database projects; however you can add your job by calling dbo.sp_add_job stored procedure.

The easiest way will be:

  1. Create your job by SSMS and copy the script.

  2. Control the job is already exist at database or not at your post deployment script. if it is exist delete at first; or you are going to have an error during deployment. you can do something like below:

 DECLARE @JobID BINARY(16)
    SELECT @JobID = job_id
    FROM msdb.dbo.sysjob
    WHERE (name = N'NameOfYourJob')
    IF (@JobIDdel IS NOT NULL)
    BEGIN
      EXECUTE msdb.dbo.sp_delete_job @job_name = N'NameOfYourJob'
    END
  1. Paste your script for creating job to post deployment script.

For feeling more safe you can check the job is working at the moment or not and you can disable job also before deleting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top