快照复制显示错误"该步骤未正确定义,因此无法运行"

时间:2018-04-24 19:12:18

标签: sql-server database-replication snapshot

我正在尝试添加" SQL Server代理"作业到其中包含SQL Server 2008 R2的新数据库服务器。此作业在"组"上进行快照复制。表,然后将快照分发给另一台服务器中的订户。不幸的是,该作业在创建快照的步骤中失败。它一直给我这个错误信息:

  

步骤定义不正确,因此无法运行

失败的步骤是:

  • 类型:复制快照
  • 命令: -Publisher [DBSERVER-NEW] -PublisherDB [ProductionDB] -Distributor [DBSERVER-NEW] -Publication [Replicate_Groups_Table] -DistributorSecurityMode 1

我在命令提示符下尝试了相同的命令,运行正常。我试过的命令是:

snapshot.exe -Publisher [DBSERVER-NEW] -PublisherDB [ProductionDB] -Distributor [DBSERVER-NEW] -Publication [Replicate_Groups_Table] -DistributorSecurityMode 1

因此,命令本身应该没问题。

顺便说一下," snapshot.exe"我使用的命令在此文件夹中:

  

C:\ Program Files \ Microsoft SQL Server \ 100 \ COM

我已经检查了该步骤的高级页面,看起来很好:

  • 成功:转到下一步
  • 失败时:退出作业报告失败

我重启了新的数据库服务器。但这并没有帮助。

请注意,作业正在SQL Server代理的上下文中运行。我已经为SQL Server代理分配了一个本地管理员用户帐户。因此,作业应具有所需的所有访问权限。

请注意,我在旧的数据库服务器(SQL Server 2000)中运行正常。我还在2015年之前在SQL Server 2008 R2数据库服务器上做过一次这样的事情。那也很好。因此,我不知道为什么这次我有这么多麻烦。

我怎样才能准确找出工作的抱怨?

如果有什么我应该尝试的,请告诉我。提前谢谢。

杰伊陈

作为参考,作业的定义如下:

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

2 个答案:

答案 0 :(得分:1)

Here我读到了:

  

从命令提示符或批处理文件中,启动复制   快照代理程序通过运行snapshot.exe,指定以下内容   命令行参数:

所以也许尝试添加&#34; snapshot.exe&#34;在你的第一个参数之前。

答案 1 :(得分:0)

请参阅我对用户1443098的评论。

基本上,msdb.dbo.sysjobstops中记录的作业步骤缺少“服务器”名称。

我的建议不是手动创建整个作业。应该使用向导生成基本作业以确保它首先工作,然后自定义作业以添加我们自己的东西。

另一个建议是将作业的步骤(在msdb.dbo.sysjobstops中)与已知良好作业中的步骤进行比较,以确定是否有任何遗漏。

如果上述方法均无效,请尝试使用user1443098建议的内容。那就是将“snapshot.exe”添加到命令的开头。这还涉及将步骤从“复制快照”更改为“操作系统(CmdExec)”,并确保搜索PATH包含“snapshot.exe”文件所在的文件夹。当然,在将命令合并到SQL Server代理作业之前,需要先在命令提示符中测试整个命令。

希望这有帮助。