Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to execute a ssis pkg and set a ssis variable value in that pkg from TSQL Expand / Collapse
Author
Message
Posted Tuesday, July 16, 2013 1:49 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 16, 2014 2:40 PM
Points: 336, Visits: 757
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

Post #1474276
Posted Tuesday, July 16, 2013 2:31 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:37 AM
Points: 13,250, Visits: 11,028
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




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1474291
Posted Tuesday, July 16, 2013 2:45 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 16, 2014 2:40 PM
Points: 336, Visits: 757
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
Post #1474296
Posted Tuesday, July 16, 2013 2:47 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:37 AM
Points: 13,250, Visits: 11,028
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.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1474297
Posted Tuesday, July 16, 2013 2:58 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 16, 2014 2:40 PM
Points: 336, Visits: 757
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
Post #1474300
Posted Tuesday, July 16, 2013 3:08 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:37 AM
Points: 13,250, Visits: 11,028
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.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1474304
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse