SSIS 2016 system variable System::ErrorDescription missing? - ssis

Using SSIs 2016 trying to set an input parameter to a sql task to System::ErrorDescription, but that variable isnt listed. Is this variable not used any longer?
I have sql task that, if it fails, I want to log the error desciption to a table. Yes, I know I can enable logging, but I want also use this message in another task.
[Edit]
I think this variable is only visible within the context of an event handler such as OnError, correct?

The System::ErrorDescription variable is not available for all components, specifically it is only in the OnError, OnInformation, and OnWarning event handlers.
https://learn.microsoft.com/en-us/sql/integration-services/system-variables?view=sql-server-2016

Related

How to throw an exception in Azure Logic Apps?

Is it possible to throw an exception in a Logic App?
Specifically, I'm trying to throw an exception inside of a scope. Then in the run after of the scope I'd check if it failed and inspect it for errors. I tried using a terminate inside of a scope, but that terminates the entire logic app run.
As an updated solution we can use Terminate control, Terminate control has 3 status: Failed, Canceled, and Succeeded.
Quick Answer (TL;DR)
Problem: MSFT Azure logic app throwing exceptions
Workaround: Use logic app Scope element to simulate throwing exceptions
Create a scope element to use as your "try-catch" block
Force the scope element to fail with an invalid command to simulate an exception
Allow the scope element to fail naturally and that will count as an exception too
Detailed Answer
Context
MSFT Azure logic app workflows
live version as of 2020-06-14
Problem
Scenario: Developer wishes to throw an exception or use try-catch semantics in a logic app
Solution
As of this writing, the live version of the product does not support this feature. There is a workaround.
Workaround
Use logic app scope element
add a conditional statement inside the scope element
If the conditional statement meets the failure condition, force an exception with a deliberately invalid command
for example create a variable assignment with the value int('__ERROR__')
If the conditional statement does not meet the failure condition, do nothing
The rest of the logic app consists of two paths
The first path runs on the success of the scope element
The second path runs on the failure of the scope element (failed, skipped, timed out)
Example
Create a scope element as a "try-catch" block
Create a variable compose element with an invalid command
int('__ERROR__') ## this will cause the enclosing scope to fail
## the string __ERROR__ cannot be cast to integer
Respond to exit status of the Scope element enclosing your exception
See also
related SO answer about forcing exceptions https://stackoverflow.com/a/61101945/42223
No, there is no Action or Connector directly analogous to something like a throw in C#.
The closest you can get right now would be to do something like use another LogicApp instead of a scope from which you can return a specific status code.
It seems like there still is no option for this inside Logic App or its little brother Power Automate / Microsoft Flow.
The way I have come up with and have used in some flows, is I simply add an action for something I know for a fact will fail.
The simplest (and probably the cheapest as the built-in actions cost less in Logic Apps, even if we are talking fractions of a dollar here either way) is probably to initialize a variable, e.g. called ThrowException with type of integer.
Then a "Set variable" action is added wherever I want my flow to fail, where I set the value (remember it is of type integer) to any string expression. I simply use the expression string('Exception').
Simple example screenshot
Since the value is set via an expression this is still a valid template, but will fail upon runtime when the value is actually being set.
After this, simply use parallel branches, with appropriate Run After settings, as usual.

Error: The variable "System::ErrorDescription" was not found in the Variables collection. The variable might not exist in the correct scope

I have created a SSIS package for migrating data from one sql server database to another. The tasks are created in a sequence container.
I have created events in the event handler and added the send mail task for sending email and getting the following error. I get this error even when I try to evaluate the expression in the expression builder. Please note that I am getting the error on the onTaskFailed event handler. I think the system error variables are not accessible in that event. Do I really need that event handler
I can see the variable in the collection. Not sure of how the scope affects it.
This is definitely a scoping issue. The system variable 'ErrorDescription' is only avialable at 'OnError' event handler and can't be used in 'TaskFailed' event handler. As to the question of if you need it or not, that is something your business logic should dictate. I would suggest to move your code to 'OnError' event handler.

Integration services : Implement onSuccess event in ssis. How to ?

I have a sequence container with multiple Execute package tasks in it. For each task what I want is to update a record in SQL table if the package executes successfully.
I looked into event handling but there is no OnSuccess event in SSIS. I have used OnError event handling for it and that seems to be working fine.
Is there a possibility to do that?
I would put the update in an execute package task right after the execute package task. If there is a failure the update will not happen.
Are you opposed to adding a component after your SQL query? This is using all scripts but the same principle can be applied if you wanted to use a Execute SQL Task or any other type of component. That way you can still run parallel, your table would be updated with ONLY the tasks that completed and your next item(s) in your control flow would still be valid
I see 2 possible ways of doing this
1: You can wrap each Execute package tasks inside its own container
and then
use precedence constraints with success and failure
2 You can inside each package handle your flow with update statements when it succeeds with constraints also.
But when your package task 1 fails, the main container will also fail and then your package will also fail, so consider setting maxmiumerrorcount to -1 or 999.
Then your MasterPackage will not fail, and your log will control for you which packages has failed.

SSIS SQL Task Map Result Set to Project Parameter

I am implementing a custom auditing framework, logging ETL events such as start, end, error, insertrows etc.
As well as logging at a package level, I'm implementing "session logging" where a sequence of package executions, i.e. a controller package that executes several packages, is a session. In order to keep track of the "session", the stored procedures always return a SessionLogID.
I was hoping I could map this result set to a project parameter as otherwise, I will have to save it to a user var and then pass it around between packages via parameters. This will mean every single package will have a Package Parameter and User Variable called SessionLogID. I don't want to do this if I don't need to.
Open to other suggestions.
Thanks,
Adam
Parameters cannot change at runtime. They are a set once kind of deal whereas variables can change at any time. You can set the variable once in the parent package and map the variable to the child package's using a parameter.

Can't reference SSIS variables in script task

I have a very simple SSIS package and an absurdly simple Script task
var x = Dts.Variables["User::OrderPath"];
That fails with:
The element cannot be found in a collection. This error happens when
you try to retrieve an element from a collection on a container during
execution of the package and the element is not there.
I have a variable, OrderPath, that is scoped to the package. Any time I try to add the variable to the script's ReadOnlyVariables, it disappears whenever I execute the task.
This really shouldn't be this difficult so I assume I'm missing something monumentally basic. Any idea what that might be?
When accessing variables through the Dts.Variables collection, you do not prefix the variable name with the namespace; thus
var x = Dts.Variables["User::OrderPath"];
fails, while
var x = Dts.Variables["OrderPath"];
succeeds. (Assuming, of course, that OrderPath is added to either the ReadWriteVariables or ReadOnlyVariables task properties.)
See Using Variables in the Script Task in MSDN for another example.