从远程服务器上的另一个作业调用SQL代理作业?

时间:2010-06-25 12:36:29

标签: sql-server sql-server-2005 sql-server-2008 sql-agent

有没有办法在不使用链接服务器的情况下从远程服务器上的另一个作业触发作业?

原因是被触发的作业在2008年执行SSIS包。调用作业驻留在2005服务器上,因此无法直接执行作业。

服务器没有链接,我希望有办法从另一个调用一个。

3 个答案:

答案 0 :(得分:3)

在SQL Agent中使用“cmdexec(操作系统)”类型,然后使用dtexec \ f“.....”命令行来执行SSIS 2008包。这个糟糕的工作!

将dtsx文件导出到2005服务器框,并使用dtexec实用程序从命令行调用dtsx。

答案 1 :(得分:2)

不确定这是否有效。创建一个调用sp_start_job

的http端点

http://technet.microsoft.com/en-us/library/ms181591.aspx

http://msdn.microsoft.com/en-us/library/ms186757.aspx

答案 2 :(得分:1)

以下代码应该有效,假设您有权执行xp_cmdshell。只需要替换@job_name和@server_name的文本。

USE master 
GO 
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1 
GO 
-- To update the currently configured value for advanced options.
RECONFIGURE WITH OVERRIDE 
GO
-- To disable the feature.
EXEC sp_configure 'xp_cmdshell', 1 
GO 
-- To update the currently configured value for this feature.
RECONFIGURE WITH OVERRIDE 
GO 


declare @retcode int 
declare @job_name varchar(300) 
declare @server_name varchar(200) 
declare @query varchar(8000) 
declare @cmd varchar(8000) 

set @job_name = 'hodes - grant user permissions' ------------------Job name goes here. 
set @server_name = 'msc-dbs04' ------------------Server name goes here. 

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 = xp_cmdshell @cmd 

if @retcode <> 0 or @retcode is null 
begin 
print 'xp_cmdshell @retcode = '+isnull(convert(varchar(20),@retcode),'NULL @retcode') 
end 

USE MASTER
GO
-- To update the currently configured value for advanced options.
RECONFIGURE WITH OVERRIDE
GO
-- To disable the feature.
EXEC sp_configure 'xp_cmdshell', 0
GO
-- To update the currently configured value for this feature.
RECONFIGURE WITH OVERRIDE
GO
-- To do not allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 0
GO
-- To update the currently configured value for advanced options.
RECONFIGURE WITH OVERRIDE
GO