2010-06-18 81 views
2

我有一個維護計劃,看起來像這樣...Sql Server的維護計劃任務和完成

Client 1 Import Data (Success) -> Process Data (Success) -> Post Process (Completion) -> Next Client 
Client 2 Import Data (Success) -> Process Data (Success) -> Post Process (Completion) -> Next Client 
Client N ... 

導入數據和處理數據的呼籲工作和提交過程是一個執行SQL任務。 如果導入數據或過程數據失敗,它將轉到下一個客戶端導入數據...

導入數據和過程數據都是包含使用內置SQL日誌記錄提供程序的SSIS包的作業。

我用,因爲它代表的配置期望是:

  1. 客戶端1導入數據運行:失敗 - >客戶端2導入數據|成功過程數據
  2. 過程數據運行:失敗 - >客戶端2導入數據|成功的後期處理
  3. 後的進程中運行:完成 - >成功或失敗 - >下一步客戶端導入數據

這不是我在日誌中我看到,雖然...... 我看到幾個客戶端導入數據SSIS日誌條目,然後是幾個後期處理日誌條目,然後返回到客戶端導入數據!精氨酸!

我在做什麼錯?我認爲客戶端1導入數據的「成功」部分不會啓動,直到它成功完成!雖然日誌似乎表明,但...

我真的需要這些任務是連續的不是併發的。這可能嗎?

謝謝!

回答

0

對我來說,解決方案最終不是使用內置的「執行SQL Server代理作業任務」,而是使用「執行T-SQL語句任務」並調用存儲過程,直到完成阻塞...

甜成功:-)

CREATE PROCEDURE [dbo].[SQLJob_RunBlocking] 
(
    @JobName SYSNAME 
) 
AS 
BEGIN 
    -- running a job returns before the job is complete 
    -- this procedure will run the job and loop until its status is complete 
    SET NOCOUNT ON; 

    DECLARE @JobStatus INT; 

    -- start job 
    EXECUTE msdb.dbo.sp_start_job @job_name = @JobName; 

    -- loop until status is complete 
    WHILE ISNULL(@JobStatus, 0) != 4 BEGIN 
     WAITFOR DELAY '00:00:01'; 

     EXECUTE dbo.SQLJob_GetStatus @job_name = @JobName, @select_data = 0, @execution_status = @JobStatus OUTPUT; 
    END 
END 

而且......

CREATE PROCEDURE [dbo].[SQLJob_GetStatus] 
(
    @job_name SYSNAME 
    ,@select_data INT = 0 
    ,@execution_status INT = NULL OUTPUT 
) 
AS 
BEGIN 
    SET NOCOUNT ON; 

    -- http://www.siccolo.com/Articles/SQLScripts/how-to-create-sql-to-sql-job-execution-status.html 
    /* 
     Is the execution status for the jobs. 
     Value Description 
     0 Returns only those jobs that are not idle or suspended. 
     1 Executing. 
     2 Waiting for thread. 
     3 Between retries. 
     4 Idle. 
     5 Suspended. 
     7 Performing completion actions 
    */ 

    DECLARE @job_id UNIQUEIDENTIFIER 
     ,@is_sysadmin INT 
     ,@job_owner SYSNAME; 

    SELECT @job_id = job_id FROM msdb.dbo.sysjobs_view where name = @job_name; 
    SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0); 
    SELECT @job_owner = SUSER_SNAME(); 

    CREATE TABLE #xp_results (
     job_id    UNIQUEIDENTIFIER NOT NULL, 
     last_run_date   INT    NOT NULL, 
     last_run_time   INT    NOT NULL, 
     next_run_date   INT    NOT NULL, 
     next_run_time   INT    NOT NULL, 
     next_run_schedule_id INT    NOT NULL, 
     requested_to_run  INT    NOT NULL, -- BOOL 
     request_source  INT    NOT NULL, 
     request_source_id  sysname   COLLATE database_default NULL, 
     running    INT    NOT NULL, -- BOOL 
     current_step   INT    NOT NULL, 
     current_retry_attempt INT    NOT NULL, 
     job_state    INT    NOT NULL 
    ); 


    IF ((@@microsoftversion/0x01000000) >= 8) -- SQL Server 8.0 or greater 
     INSERT INTO #xp_results 
     EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner, @job_id; 
    ELSE 
     INSERT INTO #xp_results 
     EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner; 

    --declare @execution_status int 
    SET @execution_status = (SELECT job_state FROM #xp_results); 

    DROP TABLE #xp_results; 

    IF @select_data = 1 
     SELECT @job_name AS 'job_name', @execution_status AS 'execution_status'; 
END 
0

嘗試將一個序列容器放置在需要在組中執行的任務中。

相關問題