January 31, 2007 at 11:56 am
i've tried having one job start another
job on a different server but
i'm having some trouble with it, and wondering if
there was another way i can do this?
seems like it would be a simple script but i'm
not familiar with it. does any one know another
way this can be accomplished without using a
dts package to do it?
thanks in advance.
_________________________
January 31, 2007 at 12:01 pm
I didn't look at the link but here's how I do it :
EXEC [LinkedServerName].msdb.dbo.sp_start_job @job_name = 'UpdateDeveloppementDatabase - Documentation'
If tat doesn't work can you specify the errors you are getting?
January 31, 2007 at 12:18 pm
thanks for the reply.
well... i can 'can' do it this way, but
i would have to create, execute the job, then
remove the linked server as we do not presently
allow the 2 servers to be linked.
step 1: sp_addlinkedserver
step 2: exec job via [linkedServername].msdb.dbo.sp_start_job @job_name = 'myjob'
step 3: remove linked server
thought that was a bit much, but i can do it that way if i need.
is there no other way?
_________________________
January 31, 2007 at 12:39 pm
Tried the same openrowset/openquery (the one which doesn't required a live linked server)?
January 31, 2007 at 12:44 pm
You can start the job on the other server using the OSQL command within an Operating System command (CmdExec) job step or using XP_CMDSHELL.
January 31, 2007 at 12:49 pm
Ya that's the solution he can't make work from the link... Got any working sample you an provide?
January 31, 2007 at 4:13 pm
Since he did not provide the actual code that he was having trouble with, or the error he was getting, it is a little hard to provide help.
"Damn it Jim, I not a mind reader!"
This code works OK for me.
-- Start_Job_on_Remote_Server.sql
declare @retcode int declare @job_name varchar(300) declare @server_name varchar(200) declare @query varchar(8000) declare @cmd varchar(8000)
set @job_name= 'My Test Job' set @server_name= 'MyRemoteServer'
set @query= 'exec msdb.dbo.sp_start_job @job_name = ''' + @job_name + '''' set @cmd= 'osql -E -S ' + @server_name + ' -Q "' + @query + '"'
print ' @job_name = ' +isnull(@job_name,'NULL @job_name') print ' @server_name = ' +isnull(@server_name,'NULL @server_name') print ' @query = ' +isnull(@query,'NULL @query') print ' @cmd = ' +isnull(@cmd,'NULL @cmd')
exec @retcode = master.dbo.xp_cmdshell @cmd
if @retcode <> 0 or @retcode is null begin print 'xp_cmdshell @retcode = '+isnull(convert(varchar(20),@retcode),'NULL @retcode') end
January 31, 2007 at 7:56 pm
You can also create a dts package to start the job..
Use EXEC SQL TASK to execute the job...
MohammedU
Microsoft SQL Server MVP
February 1, 2007 at 9:19 am
grasshopper,
your stuff worked G R E A T!!
thanks for the post!
_________________________
February 1, 2007 at 10:02 am
February 1, 2007 at 11:52 am
oops...
ok then; thanks alot MVJ!
_________________________
February 1, 2007 at 3:52 pm
You're welcome, Veteran!
February 1, 2007 at 3:57 pm
LOL.
February 2, 2007 at 4:07 am
the downside of the proposed proc is that it will start the job, even if it has been disabled !!!
Maybe it's better to implement an alert to start the job, so the connection osql-user does not need to be the job-owner or have sa-authority !
Keep in mind you'll have to stop/start sqlagent when you enable a first alert.
declare @retcode int declare @server_name varchar(200) declare @query varchar(8000) declare @cmd varchar(8000)
set @server_name= 'MyRemoteServer'
set @query= 'raiserror (yourpredifinederrornumber,10,1) with log' set @cmd= 'osql -E -S ' + @server_name + ' -Q "' + @query + '"'
print ' @job_name = ' +isnull(@job_name,'NULL @job_name') print ' @server_name = ' +isnull(@server_name,'NULL @server_name') print ' @query = ' +isnull(@query,'NULL @query') print ' @cmd = ' +isnull(@cmd,'NULL @cmd')
exec @retcode = master.dbo.xp_cmdshell @cmd
if @retcode <> 0 or @retcode is null begin print 'xp_cmdshell @retcode = '+isnull(convert(varchar(20),@retcode),'NULL @retcode') end
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
July 29, 2008 at 4:20 am
Thanx for that routine as it works great :w00t:
I realize that I may be stretching this, but would it be possible to modify this, so that the job step on the originating server WAITS for the job on the distant server to complete with SUCCESS/FAILURE?
Best regards,
Marek
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply