How to execute a ssis pkg and set a ssis variable value in that pkg from TSQL

  • I have a need to execute a ssis pkg and pass in a date for each run of the pkg to set the value of a ssis variable in the pkg. I copied the script when I right clicked the pkg on the server and clicked run package. Below is what I have but my code is incorrect for the script to run the package. Can someone help me out?

    Declare @TSQLCmd varchar(max)

    DECLARE @startdt DATETIME, @enddt DATETIME

    SET @startdt = '01/01/2013'

    SET @enddt = '01/30/2013'

    --DECLARE @dates TABLE (MyDate DATETIME)

    --INSERT INTO @dates VALUES (@startdt)

    WHILE @startdt < @enddt

    BEGIN

    Select @TSQLCmd = 'EXEC xp_cmdshell ''/DTS "\"\MSDB\HDC\"" /SERVER C9100970E1DB44B /CHECKPOINTING OFF /REPORTING V /set \package.variables[User::HDCTodaysDate].Value;"' + CONVERT(VARCHAR(10), @startdt, 101) + '"'''

    print @TSQLCmd

    SET @startdt = @startdt + 1

    --INSERT INTO @dates VALUES (@startdt)

    END

  • Any error messages?

    edit: when I look for examples of SSIS packages being executed by xp_cmdshell, I see that they are escaping the " in their code. Maybe you need to add that as well.

    Example: http://geekswithblogs.net/stun/archive/2010/02/24/execute-ssis-package-from-stored-procedure-with-parameters-using-dtexec-utility.aspx

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I'm getting an error saying DTS isnt a command. I can find all kinds of examples on how to execute a package saved as a file but I cant seem to find any on ruunning the package that haas been deployed to an integration server. If someone can show me that I believe I can work everything out

  • DTS isn't a command. It's a switch telling dtexec that the package is stored in the SSIS package store. You need to put dtexec at the start of your command line.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I changed my code to the following to mak it easier to debug...Im posting my error afterwards. The SSIS package is deploy to an integration server:

    Declare @TSQLCmd varchar(3000)

    DECLARE @startdt DATETIME, @enddt DATETIME

    Declare @ReturnCode INT

    Select @TSQLCmd = 'dtexec /DTS "\"\MSDB\HDC\"" /SERVER C9100970E1DB44B /CHECKPOINTING OFF /REPORTING V /set \package.variables[User::HDCTodaysDate].Value;"' + CONVERT(VARCHAR(10), '07/16/2013', 101) + '"'''

    --print @TSQLCmd

    EXEC @ReturnCode = xp_cmdshell @TSQLCmd

    My error is as follows:

    Microsoft (R) SQL Server Execute Package Utility

    Version 11.0.3369.0 for 32-bit

    Copyright (C) Microsoft Corporation. All rights reserved.

    NULL

    Started: 4:55:51 PM

    Error: 2013-07-16 16:55:53.49

    Code: 0xC0016016

    Source: HDC

    Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that

    the correct key is available.

    End Error

    Error: 2013-07-16 16:55:53.68

    Code: 0xC0016016

    Source: HDC

    Description: Failed to decrypt protected XML node "PassWord" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the

    correct key is available.

    End Error

    Error: 2013-07-16 16:55:53.78

    Code: 0xC0016016

    Source: HDC

    Description: Failed to decrypt protected XML node "PassWord" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the

    correct key is available.

    End Error

    Error: 2013-07-16 16:55:53.78

    Code: 0xC0016016

    Source: HDC

    Description: Failed to decrypt protected XML node "PassWord" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the

    correct key is available.

    End Error

    Error: 2013-07-16 16:55:53.78

    Code: 0xC0016016

    Source: HDC

    Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that

    the correct key is available.

    End Error

    Info: 2013-07-16 16:55:54.99

    Code: 0x4004300A

    Source: Data Flow Task SSIS.Pipeline

    Description: Validation phase is beginning.

    End Info

    Progress: 2013-07-16 16:55:54.99

    Source: Data Flow Task

    Validating: 0% complete

    End Progress

    CustomEvent: 2013-07-16 16:55:54.99

    Source: Data Flow Task

    Name: OnPipelinePreComponentCall

    Description: Data flow engine will call a component method.

    End CustomEvent

    Error: 2013-07-16 16:55:55.31

    Code: 0xC0202009

    Source: HDC Connection manager "C9100970E1DB44B.HDC.HDC_Worker1"

    Description: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E4D.

    An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E4D Description: "Login failed for user 'HDC_Worker'.".

    End Error

    Error: 2013-07-16 16:55:55.33

    Code: 0xC020801C

    Source: Data Flow Task OLE DB Destination [2]

    Description: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "C9100970E1DB44B.HDC.HDC_Worker1" failed with error code 0xC0202009. There may be error messages posted befor

    e this with more information on why the AcquireConnection method call failed.

    End Error

    CustomEvent: 2013-07-16 16:55:55.33

    Source: Data Flow Task

    Name: OnPipelinePostComponentCall

    Description: Data flow engine has finished a call to a component method.

    End CustomEvent

    Error: 2013-07-16 16:55:55.33

    Code: 0xC0047017

    Source: Data Flow Task SSIS.Pipeline

    Description: OLE DB Destination failed validation and returned error code 0xC020801C.

    End Error

    Progress: 2013-07-16 16:55:55.33

    Source: Data Flow Task

    Validating: 50% complete

    End Progress

    Error: 2013-07-16 16:55:55.33

    Code: 0xC004700C

    Source: Data Flow Task SSIS.Pipeline

    Description: One or more component failed validation.

    End Error

    Error: 2013-07-16 16:55:55.33

    Code: 0xC0024107

    Source: Data Flow Task

    Description: There were errors during task validation.

    End Error

    DTExec: The package execution returned DTSER_FAILURE (1).

    Started: 4:55:51 PM

    Finished: 4:55:55 PM

    Elapsed: 3.448 seconds

    NULL

  • Apparently you have some encryption going on in your package. Open it up and take a look at the package protection level.

    Either turn it off or set it to a more appropriate level. You might have to supply a password in your command line.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply