SQL Server - sp_verify_job @name already exists

痞子三分冷 提交于 2020-02-25 05:50:29

问题


I am trying to create a job on a SQL Server 2017 instance from an SSIS package. This SSIS package was created from the Import and Export wizard. All the job does is update a table from an Excel file. In the Import wizard, the job runs fine and the table is successfully update. However, when I add the package to a job and try to run the code, I get the following error message: "Msg 14261, Level 16, State 1, Procedure sp_verify_job, Line 57 [Batch Start Line 2] The specified @name ('Optimus prime') already exists." I have tried to run it with proxy credentials, which have access to SSIS then tried to rename the job several times with no success. I have also tried to SET the value of @name to NULL to no avail.

Below is the code for the job:

USE [msdb]
GO

/****** Object:  Job [Optimus prime]    Script Date: 2/4/2020 10:08:08 AM ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [Data Collector]    Script Date: 2/4/2020 10:08:08 AM ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Data Collector' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Data Collector'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'Optimus prime', 
        @enabled=1, 
        @notify_level_eventlog=0, 
        @notify_level_email=0, 
        @notify_level_netsend=0, 
        @notify_level_page=0, 
        @delete_level=0, 
        @description=N'Imports Excel tables from SNOW and DIACAR', 
        @category_name=N'Data Collector', 
        @owner_login_name=N'EU\z-georgica.topor', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Step 1]    Script Date: 2/4/2020 10:08:08 AM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Step 1', 
        @step_id=1, 
        @cmdexec_success_code=0, 
        @on_success_action=1, 
        @on_success_step_id=0, 
        @on_fail_action=2, 
        @on_fail_step_id=0, 
        @retry_attempts=0, 
        @retry_interval=0, 
        @os_run_priority=0, @subsystem=N'SSIS', 
        @command=N'/SQL "\"\DIACAR Import\"" /SERVER "\"ART-OF-WV0006\"" /CONNECTION DestinationConnectionOLEDB;"\"Data Source=(local);Initial Catalog=Terminator;Provider=SQLNCLI11;Integrated Security=SSPI;Auto Translate=false;\"" /CONNECTION SourceConnectionExcel;"\"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\z-georgica.topor\Desktop\POC1.xlsx;Extended Properties=\"\"EXCEL 12.0 XML;HDR=YES\"\";\"" /CHECKPOINTING OFF /REPORTING E', 
        @database_name=N'master', 
        @flags=0, 
        @proxy_name=N'SSIS'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO

Thanks in advance for the help!


回答1:


The name in the error message is the job name and not the @name variable which is the job category name in the code. Your question suggests you already created the job using the import/export wizard, and now it fails through SSIS because it already exists. So, try:

Changing the @job_name variable or Dropping the job before trygin to create it again



来源:https://stackoverflow.com/questions/60053153/sql-server-sp-verify-job-name-already-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!