2010-06-25 58 views
3

有沒有辦法在不使用鏈接服務器的情況下從遠程服務器上的另一個作業觸發作業?從遠程服務器上的另一個作業調用SQL代理作業?

其原因是被觸發的作業在2008年執行了SSIS包。調用作業駐留在2005服務器上,因此無法直接執行作業。

服務器沒有鏈接,我希望有一種方法可以從另一箇中調用。

+0

你能解釋一下情況嗎?如果您嘗試通過鏈接服務器執行它,或者出於某種原因不想創建一個服務器,它會不工作嗎? – 2010-06-25 12:42:08

+0

我相信這些服務器沒有鏈接,因爲一個數據庫服務器僅用於通過非標準端口與DMZ中的Web服務器進行通信。另一個是內部數據庫服務器。我不知道鏈接服務器是否會影響到這一點,但這不會是我的問題,如果可能的話,我想盡快解決。 – Feckmore 2010-06-25 12:56:36

回答

3

在SQL代理中使用類型「cmdexec(操作系統)」,然後使用dtexec \ f「.....」命令行用於執行SSIS 2008程序包。這個短暫的工作!

將dtsx文件導出到2005服務器框,並使用dtexec實用程序從命令行調用dtsx。

+0

2008 SSIS包不能在SQL Server 2005中執行。聽起來好像這就是你的建議。我只是誤解了嗎? – Feckmore 2010-06-25 13:31:26

+0

只有當您有一個SQL Server綁定的包時,才能這樣做。您可以從文件系統執行軟件包。我建議使用它配置文件導出dtsx文件,然後就像使用命令行執行dtexec utitlity在具有類型操作系統(cmdexec)的代理作業步驟中執行它一樣。這個短暫的工作! – Baaju 2010-06-25 13:52:21

1

的folllowing代碼應該工作,假設你有權限執行xp_cmdshell一個http終點。只需要替換@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