Tuesday, March 27, 2012

EXEC sp_start_job Remote Server

I am trying to create a centralized job monitoring system that can be
managed by some operators to restart a job if it fails. Everything
will be running on one system but I need to invoke remote jobs on
remote system. I am having trouble starting a job on a remote system
even if I have the permissions to do so.
[Code]
DECLARE @.SQLCMD VARCHAR(MAX)
SET @.SQLCMD = ''
DECLARE @.SystemNameVARCHAR(50)
DECLARE @.JobNameVARCHAR(50)
DECLARE @.StepNameVARCHAR(50)
SET @.SystemName = RemoteServer
SET @.JobName = Explode
SET @.StepName = BadStep
SET @.SQLCMD = '' + @.SystemName + '.msdb.dbo.sp_start_job @.job_name =
''' + @.JobName + ''', @.step_name = ''' + @.StepName + ''''
PRINT @.SQLCMD
[/code]
This will generate the following
RemoteServer.msdb.dbo.sp_start_job @.job_name = 'Explode', @.step_name =
'Bad'
If i run this command as an adhoc command, it will execute on the
RemoteServer and start the job at the step. However for the SP i am
writing this does not work
[Code]
EXEC @.SQLCMD
EXEC msdb.dbo.sp_start_job @.job_name = 'Explode', @.step_name = 'Bad'
[/Code]
This error appers.
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'msdb.dbo.sp_start_job @.job_name =
'Explode', @.step_name = 'Bad''.
If I try to run it this way, I get the following error message.
EXEC msdb.dbo.sp_start_job @.server_name = 'dbdev4', @.job_name =
'Explode', @.step_name = 'Bad'
Msg 14262, Level 16, State 1, Procedure sp_verify_job_identifiers,
Line 67
The specified @.job_name ('Explode') does not exist.
Any ideas
Thanks
-Matt-
Hi Matt
"Matthew" wrote:

> I am trying to create a centralized job monitoring system that can be
> managed by some operators to restart a job if it fails. Everything
> will be running on one system but I need to invoke remote jobs on
> remote system. I am having trouble starting a job on a remote system
> even if I have the permissions to do so.
> [Code]
> DECLARE @.SQLCMD VARCHAR(MAX)
> SET @.SQLCMD = ''
> DECLARE @.SystemNameVARCHAR(50)
> DECLARE @.JobNameVARCHAR(50)
> DECLARE @.StepNameVARCHAR(50)
> SET @.SystemName = RemoteServer
> SET @.JobName = Explode
> SET @.StepName = BadStep
> SET @.SQLCMD = '' + @.SystemName + '.msdb.dbo.sp_start_job @.job_name =
> ''' + @.JobName + ''', @.step_name = ''' + @.StepName + ''''
> PRINT @.SQLCMD
> [/code]
> This will generate the following
> RemoteServer.msdb.dbo.sp_start_job @.job_name = 'Explode', @.step_name =
> 'Bad'
> If i run this command as an adhoc command, it will execute on the
> RemoteServer and start the job at the step. However for the SP i am
> writing this does not work
> [Code]
> EXEC @.SQLCMD
> EXEC msdb.dbo.sp_start_job @.job_name = 'Explode', @.step_name = 'Bad'
> [/Code]
> This error appers.
> Msg 2812, Level 16, State 62, Line 1
> Could not find stored procedure 'msdb.dbo.sp_start_job @.job_name =
> 'Explode', @.step_name = 'Bad''.
Try:
EXEC ( @.SQLCMD )
or
EXEC RemoteServer.msdb.dbo.sp_start_job @.job_name = 'Explode', @.step_name =
'Bad'

> If I try to run it this way, I get the following error message.
> EXEC msdb.dbo.sp_start_job @.server_name = 'dbdev4', @.job_name =
> 'Explode', @.step_name = 'Bad'
> Msg 14262, Level 16, State 1, Procedure sp_verify_job_identifiers,
> Line 67
> The specified @.job_name ('Explode') does not exist.
> Any ideas
> Thanks
> -Matt-
John

No comments:

Post a Comment