0

Recently I faced an issue in SQL Server Agent Job. The error is "Login Time Out Expired". I have analyzed it. It seems like the server name mentioned on the SSIS config file is wrong. I have corrected the server name now the job runs fine.

Our job design - SQL Server Agent Job invokes an SSIS package along with its Config file. The actual problem is we have lot of sql server agent jobs (200 + jobs). All are running on its own schedule. Currently we are fixing these issues as soon as we get an error in the Job history. This is purely a manual approach. This is one of the environment. We have almost 10 plus environments which have the same set of jobs.

I am looking for an approach where we can pre validate all the config files configured on the SQL Server agent jobs and report the files which have the incorrect server names or incorrect file paths. As you know, doing this task manually is an headache process even while doing this we may miss some jobs / create other issues as well.

Is any way we can validate the config files prior to running the SQL jobs.

jarlh
  • 42,561
  • 8
  • 45
  • 63
StackUser
  • 5,370
  • 2
  • 24
  • 44

1 Answers1

0

You can get the sqlagent job steps information by querying the msdb tables. In that, you can find out, which configuration file is being used in the job step.

Refer to sql agent jobs documentation

SELECT
    [sJOB].[job_id] AS [JobID]
    , [sJOB].[name] AS [JobName]
    , [sJSTP].[step_uid] AS [StepID]
    , [sJSTP].[step_id] AS [StepNo]
    , [sJSTP].[step_name] AS [StepName]
    , CASE [sJSTP].[subsystem]
        WHEN 'ActiveScripting' THEN 'ActiveX Script'
        WHEN 'CmdExec' THEN 'Operating system (CmdExec)'
        WHEN 'PowerShell' THEN 'PowerShell'
        WHEN 'Distribution' THEN 'Replication Distributor'
        WHEN 'Merge' THEN 'Replication Merge'
        WHEN 'QueueReader' THEN 'Replication Queue Reader'
        WHEN 'Snapshot' THEN 'Replication Snapshot'
        WHEN 'LogReader' THEN 'Replication Transaction-Log Reader'
        WHEN 'ANALYSISCOMMAND' THEN 'SQL Server Analysis Services Command'
        WHEN 'ANALYSISQUERY' THEN 'SQL Server Analysis Services Query'
        WHEN 'SSIS' THEN 'SQL Server Integration Services Package'
        WHEN 'TSQL' THEN 'Transact-SQL script (T-SQL)'
        ELSE sJSTP.subsystem
      END AS [StepType]
    , [sPROX].[name] AS [RunAs]
    , [sJSTP].[database_name] AS [Database]
    , [sJSTP].[command] AS [ExecutableCommand]
    , CASE [sJSTP].[on_success_action]
        WHEN 1 THEN 'Quit the job reporting success'
        WHEN 2 THEN 'Quit the job reporting failure'
        WHEN 3 THEN 'Go to the next step'
        WHEN 4 THEN 'Go to Step: ' 
                    + QUOTENAME(CAST([sJSTP].[on_success_step_id] AS VARCHAR(3))) 
                    + ' ' 
                    + [sOSSTP].[step_name]
      END AS [OnSuccessAction]
    , [sJSTP].[retry_attempts] AS [RetryAttempts]
    , [sJSTP].[retry_interval] AS [RetryInterval (Minutes)]
    , CASE [sJSTP].[on_fail_action]
        WHEN 1 THEN 'Quit the job reporting success'
        WHEN 2 THEN 'Quit the job reporting failure'
        WHEN 3 THEN 'Go to the next step'
        WHEN 4 THEN 'Go to Step: ' 
                    + QUOTENAME(CAST([sJSTP].[on_fail_step_id] AS VARCHAR(3))) 
                    + ' ' 
                    + [sOFSTP].[step_name]
      END AS [OnFailureAction]
FROM
    [msdb].[dbo].[sysjobsteps] AS [sJSTP]
    INNER JOIN [msdb].[dbo].[sysjobs] AS [sJOB]
        ON [sJSTP].[job_id] = [sJOB].[job_id]
    LEFT JOIN [msdb].[dbo].[sysjobsteps] AS [sOSSTP]
        ON [sJSTP].[job_id] = [sOSSTP].[job_id]
        AND [sJSTP].[on_success_step_id] = [sOSSTP].[step_id]
    LEFT JOIN [msdb].[dbo].[sysjobsteps] AS [sOFSTP]
        ON [sJSTP].[job_id] = [sOFSTP].[job_id]
        AND [sJSTP].[on_fail_step_id] = [sOFSTP].[step_id]
    LEFT JOIN [msdb].[dbo].[sysproxies] AS [sPROX]
        ON [sJSTP].[proxy_id] = [sPROX].[proxy_id]
ORDER BY [JobName], [StepNo]

Now, you need to look into Executable command to see the exact configuration file being used in the SSIS execution and accordingly take action.

[ExecutableCommand]: The actual command which will be executed by the subsystem.

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
  • Thank you for your response. This query definitely helps me. However my problem here is I want to find the config files which has incorrect server names. For ex, lets say the data source in config file on the dev environment should point to dev but in some files it has been pointing to some other env. I want to figure out only those config files so that I can apply fix accordingly in one go. – StackUser Feb 23 '22 at 09:33
  • As servernames are defined at config level, I would suggest you to first map : Job, Config, job environment. Now, you open the unique config files and see if they have to be corrected. As you are not using SSIS Environments, you have to go at config file level to find out the environment the config file is pointing to. – Venkataraman R Feb 23 '22 at 09:51