Reputation: 4264
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
Upvotes: 5
Views: 3001
Reputation: 6911
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:
Create your job by SSMS and copy the script.
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
For feeling more safe you can check the job is working at the moment or not and you can disable job also before deleting.
Upvotes: 0
Reputation: 5899
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.
Upvotes: 1