I am trying to add a "SQL Server Agent" job to a new database server that has SQL Server 2008 R2 in it. This job does snapshot replication on a "groups" table, and then distributes the snapshot to a subscriber in another server. Unfortunately that job fails at the step that makes a snapshot. It keeps giving me this error message:
The step is improperly defined and so could not be run
The step that fails is this:
- Type: Replication Snapshot
- Command: -Publisher [DBSERVER-NEW] -PublisherDB [ProductionDB] -Distributor [DBSERVER-NEW] -Publication [Replicate_Groups_Table] -DistributorSecurityMode 1
I tried the same command at the command prompt, and it ran fine. The command that I tried was:
snapshot.exe -Publisher [DBSERVER-NEW] -PublisherDB [ProductionDB] -Distributor [DBSERVER-NEW] -Publication [Replicate_Groups_Table] -DistributorSecurityMode 1
Therefore, the command itself should be fine.
By the way, the "snapshot.exe" command that I use is in this folder:
C:\Program Files\Microsoft SQL Server\100\COM
I have checked the Advanced page of the step, and it looks fine:
- On success: Go to the next step
- On failure: Quit the job reporting failure
I reboot the new database server. But that didn't help.
Please note that the job is running in the context of the SQL Server Agent. And I have assigned a local-admin user account to the SQL Server Agent. Therefore, the job should have all the access rights that it needs.
Please note that I have the exact same job running fine in an old database server (SQL Server 2000). And also I did this once before back in 2015 on a SQL Server 2008 R2 database serer; that was fine also. Therefore, I don't know why this time I have that much trouble with it.
How can I find out exactly what the job is complaining about?
Please let me know if there is anything that I should try next. Thanks in advance.
Jay Chan
For your reference, the definition of the job is the following:
USE [msdb]
GO
/****** Object: Job [PopulateAndDistributeGroupsTable] Script Date: 04/24/2018 15:22:54 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object: JobCategory [REPL-Snapshot] Script Date: 04/24/2018 15:22:54 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'REPL-Snapshot' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'REPL-Snapshot'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'PopulateAndDistributeGroupsTable',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'Populate "groups" table based on the group info from BonTrak.',
@category_name=N'REPL-Snapshot',
@owner_login_name=N'OURDOMAIN\Admin', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Populate groups table with group info from BonTrak] Script Date: 04/24/2018 15:22:54 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Populate groups table with group info from BonTrak',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=3,
@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'TSQL',
@command=N'delete from groups
insert into groups
select p.ProjectNum, m.Number, g.GroupID
from ProjectMaster p
inner join MechanicalData m on
p.ProjectID = m.ProjectID
inner join InstallationGroupMasterTable g on
m.MechanicalID = g.MechanicalID
where g.IsVoid = 0
order by p.ProjectNum, m.Number, g.GroupID
',
@database_name=N'ProductionDB',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Snapshot Agent startup message] Script Date: 04/24/2018 15:22:54 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Snapshot Agent startup message',
@step_id=2,
@cmdexec_success_code=0,
@on_success_action=3,
@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'TSQL',
@command=N'sp_MSadd_snapshot_history @perfmon_increment = 0, @agent_id = 3, @runstatus = 1, @comments = ''Starting agent.''',
@database_name=N'distribution',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Run snapshot agent to prepare replicating groups] Script Date: 04/24/2018 15:22:54 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Run snapshot agent to prepare replicating groups',
@step_id=3,
@cmdexec_success_code=0,
@on_success_action=3,
@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'Snapshot',
@command=N'-Publisher [DBSERVER-NEW] -PublisherDB [ProductionDB] -Distributor [DBSERVER-NEW] -Publication [Replicate_Groups_Table] -DistributorSecurityMode 1',
@database_name=N'master',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [PA-SPARE - Run distribution agent to replicate groups table] Script Date: 04/24/2018 15:22:54 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'BRANCH01DB - Run distribution agent to replicate groups table',
@step_id=4,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=3,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'Distribution',
@command=N'-Subscriber [BRANCH01DB] -SubscriberDB [ProductionDB] -Publisher [DBSERVER-NEW] -Distributor [DBSERVER-NEW] -DistributorSecurityMode 1 -PublisherDB [ProductionDB]',
@database_name=N'master',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [Detect nonlogged agent shutdown] Script Date: 04/24/2018 15:22:54 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Detect nonlogged agent shutdown',
@step_id=5,
@cmdexec_success_code=0,
@on_success_action=2,
@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'TSQL',
@command=N'sp_MSdetect_nonlogged_shutdown @subsystem = ''Snapshot'', @agent_id = 3',
@database_name=N'distribution',
@flags=0
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_jobschedule @job_id=@jobId, @name=N'Run this job very frequently',
@enabled=1,
@freq_type=8,
@freq_interval=126,
@freq_subday_type=4,
@freq_subday_interval=5,
@freq_relative_interval=0,
@freq_recurrence_factor=1,
@active_start_date=20180424,
@active_end_date=99991231,
@active_start_time=50200,
@active_end_time=175959,
@schedule_uid=N'057dbe80-e389-4d33-b6b7-f73315008a44'
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