SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
dndaughtery
dndaughtery
SSC Eights!
SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)

Group: General Forum Members
Points: 866 Visits: 1086
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


Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27207 Visits: 13268
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
dndaughtery
dndaughtery
SSC Eights!
SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)

Group: General Forum Members
Points: 866 Visits: 1086
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
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27207 Visits: 13268
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
dndaughtery
dndaughtery
SSC Eights!
SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)SSC Eights! (866 reputation)

Group: General Forum Members
Points: 866 Visits: 1086
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 "DTSTongueassword" 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 "DTSTongueassword" 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

Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27207 Visits: 13268
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search