I have a sensitive parameter in my package with a password in it. I want to use it in a Script Task, but when I try that it throws an error: Exception has been thrown by the target of an invocation. Can I use a sensitive parameter in a Script Task or Component?
Exception has been thrown by the target of an invocation. |
Solution
Yes you can read sensitive package and project parameters in the Script Task, but with a minor change in the code.
1) Lock for read
First open the Script Task editor and add the parameter to the ReadOnlyVariables field to lock it for read in the script.
ReadOnlyVariables |
2) The Script
Open the VSTA environment by clicking in the Edit Script button. In the Main method you have something like this at the moment:
// C# Code (incorrect) public void Main() { // Create string variable to store the parameter value string mySecretPassword = Dts.Variables["$Package::MySecretPassword"].Value.ToString(); // Show the parameter value with a messagebox MessageBox.Show("Your secret password is " + mySecretPassword); // Close the Script Task with success Dts.TaskResult = (int)ScriptResults.Success; }
Change the .Value in to .GetGetSensitiveValue() in order to retrieve the sensitive information. But from now on you are responsible for not leaking the sensitive information accidentally!
// C# Code (correct) public void Main() { // Create string variable to store the parameter value string mySecretPassword = Dts.Variables["$Package::MySecretPassword"].GetSensitiveValue().ToString(); // Show the parameter value with a messagebox MessageBox.Show("Your secret password is " + mySecretPassword); // Close the Script Task with success Dts.TaskResult = (int)ScriptResults.Success; }
Oops |
Can you give VB example for the same
ReplyDeleteUse the online telerik convert to translate C# to VB (and vice versa).
DeleteDim mySecretPassword As String = Dts.Variables("$Package::MySecretPassword").Value.ToString()
I have an empty value
ReplyDelete