SSIS package script logging - sql-server-2008

I am new to SSIS packages and I am trying to get logging to work from within a custom script. We have it logging the native messages from the package already but I want to add my own custom log messages to it. I see on the Microsoft.SqlServer.Dts.Pipeline.ScriptComponent class there is a Log method but I am unsure what to use for the dataCode and dataBytes arguments so I used 0 and an empty array but this did not log anything.
So how do I get the logging to work from within my script?
Are there any configurations that I need to know about to enable it?
Thanks
Note: I am working with SqlServer 2008 SP2 (not R2)

You need to make sure that the task is enabled for logging. Select SSIS > Logging... from the BIDS menu. Select your data flow task. On the Providers and Logs tab, ensure that a log provider is selected. Select the Details tab and Check the ScriptComponentLogEntry event. Note that this event is not inherited from the Package settings; so you have to select the data flow task. Now your logging should be captured.
You may also be interested in the ComponentMetaData.FireInformation method to log an information event. Here's more information on FireInformation and related methods. You may find these easier to configure, since the associated events (OnInformation for FireInformation) are inherited from the package settings. In other words, if you set logging for the OnInformation event at the package level, all tasks will log the OnInformation event.

Related

Ssis logging doesnt work in absense of folder

I have setup ssis logging to a text file. In the connection manager I have selected create file and given path as c:\logs\log.txt
Notice that log file is not generated if the log folder is absent. How to ensure that folder is created if not exists? I tried choosing create folder on connection manager but that is also not creating the log file in absence of the c:\log folder.
How to ensure folder is auto created and log is always generated?
You have a chicken and egg scenario here. Consider the following replication of your problem
I have the connection manager driven by a variable LogFileName which generates the date and time. That file lives in whatever folder is specified by LogPath and the first thing my package does is create the folder if it does not already exist. "This thing can run anywhere and all is good." I've said that plenty and have the scars to show for it.
The following shows the events you can choose to log (based on what is in my package).
I am only logging OnPostExecute events. So I'm good, right? Because the post execute event won't fire until after that File System Task has completed.
If that were the case, you wouldn't have posted a question.
The first event that a package generates is a PackageStart event. Look at that list of events - no ability to filter that out. It doesn't matter whether you want that event logged or not, the logging handlers hear the PackageStart event and record it. Always.
The specified Text file logger should be used to record the data and it's ready to record PackageStart to file... "oh that path doesn't exist."
It will exist once the very first task (File System Task, Create Folder) has completed but alas, it it too late. You either get the complete sequence of events or none.
In your Output window, you would see something like the following
SSIS package "C:\Users\bfellows\source\repos\PackageDeploymentModel\PackageDeploymentModel\ChickenAndEgg_Logging.dtsx" starting.
Error: 0xC001404B at ChickenAndEgg_Logging, Log provider "SSIS log provider for Text files": The SSIS logging provider has failed to open the log. Error code: 0x80070003.
The system cannot find the path specified.
Error: 0xC001404B at ChickenAndEgg_Logging, Log provider "SSIS log provider for Text
files": The SSIS logging provider has failed to open the log. Error code: 0x80070003.
The system cannot find the path specified.
SSIS package "C:\Users\bfellows\source\repos\PackageDeploymentModel\PackageDeploymentModel\ChickenAndEgg_Logging.dtsx" finished: Success.
The package will show your Control Flow objects as all having gone green/OK and the status message will say it "Package execution completed with success" but on the results tab, you'll have a red X showing the log provider couldn't open the log.
What do I do
Preconfigure your environments as part of the package deployment process. When we used the native logger as you're inquiring about, we had a document that laid out all that new developers/new servers needed to have done to ensure all of this stuff was laid out and configured as it needed to be.
Unless a client has a strong business case for using the classic logging methodology, I would encourage them to not use it and instead rely on the SSISDB's native logging. It's cleaner, easier to manage, no special setup required. To quote the fine folks in Cupertino - it just works

SSIS event handler script task

i have a package that has several event handlers that execute a script task on failure when the package fails.. Problem is its generating a email that i have NO IDEA how.. When the package fails it executes a stored procedure that grabs the email distribution list from a SQL table and sends an email. However one email is being sent out to ppl who are not with the company and ive been told twice to change the DL list.. I checked the SQL table and the people that are getting the email are not listed any where in the distribution list.. Is there any way to search anywhere in the package to find out how the email is being generated. Ive spent hours and hours going through the scrip tasks and the code is no where to be found
You can use the package explorer (to the right of the event handler tab) to navigate through the entire package and look at the event handlers for every executable. It's possible that there are multiple event handlers, one at the package level and maybe one defined on a particular task, which is hardcoded with email addresses.
You can also, right click on the package in the solution explorer and select View Code. This will open the package in xml, which you can then use ctrl+F to find a certain string.
Advice Section
While you didn't ask for it, please let me add a few words of guidance. Event handlers are evil for this very reason. They are a hidden GOTO that you are lucky to notice at all, even if you've developed the package in the first place.
If event handling is required, use the precedence constraints in the control flow. Throw everything in a container, connect it to the script task and define the constraint to trigger on failure.
To go one step further, keep your emails out of your ssis packages. Use SQL agent or whatever scheduler you are using to post messages about failures.

In SSIS how can I check if the package or task is being run within BIDS by using the play button or right-clicking and choosing Execute Task?

This is not the same as debug mode. I want to display a warning if the developer is actually in BIDS and not display the warning if the package is being run from a scheduled job.
You could use a script task that opens a MsgBox. The MsgBox would only open when the task is running in BIDS, if I am not mistaken.
I'm afraid what you are trying to achieve is not possible. BIDS uses the same runtime as your SSIS agent.
You could, however, set an environment variable in your package and remove it during deployment. All of this is hacky and defeats the purpose though.
There really should be no custom logic when running a package locally versus being deployed (other than configurations that might affect the execution graph).
If you are trying to prevent user-error it would be best to educate your peers and/or restrict access.
I have found but not checked that there is a system variable "System::InteractiveMode" that may be used for this. Something to check.
According to Microsoft's documentation on System Variables the InteractiveMode variable should be able to fulfil your need to determine if the package is running from BIDS or from a SQL Job.
InteractiveMode (Boolean)
Indicates whether the package is run in
interactive mode. If a package is running in SSIS Designer, this
property is set to True. If a package is running using the DTExec
command prompt utility, the property is set to False.
I created a Script task at the beginning of my Flow (in the control flow tab) with a precedence constraint on the following task. I defined System::InteractiveMode in the ReadOnlyVariables field and used the code below to display the question and process the answer.
public void Main()
{
if ((bool)Dts.Variables["InteractiveMode"].Value)
{
DialogResult button = MessageBox.Show("Are you sure you want to run the package?", "Validate", MessageBoxButtons.YesNo);
if (button == DialogResult.No)
{
Dts.TaskResult = (int)ScriptResults.Failure;
return;
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
It doesn't stop the execution like the stop button in BIDS but prevents the execution of the rest of the package. I tried to use the RunningPackage.Stop() method but in order to get the list of RunningPackages it requires to be running from SQL Server Integration Service.
I tested it from BIDS and from SQL Server integration service and it worked as expected.

SSIS Execute Package task notification if path does not exist

I have created a master control package that calls several packages using the execute package task control. I have set all the package file locations to use a sql config table which contains the file location and then used an expression to include the package name. Everything works as expected however I want to include some handlers to notify me if the package location does not exist (just in case somebody changes the path in the config table). To test I set an incorrect file name in one of the expressions which turned the execute package task control red as expected however I can't figure out how to add the notification task. I have tried all the error handler events assocaited with it but no joy plus I added a mail task to the task in question for failure and this did not execute!
Any advice greatly appreciated.
Thanks.
That's why you have OnError event handler, just configure it properly. Are you sure, you're checking Event Handlers for the package and not for one of the blocks inside?
There's a plenty of system variables with OnError scope. Check grey x in Variable window to see them. You might want to use:
- ErrorDescription
- ErrorCode
- SourceName
but choose them according to the report format.
Now in event handler create a script which will put a message into a new variable, and finally send it with send mail task.

Get package name/ID in the Log method from an SSIS Custom Logging Provider

I have a custom SSIS logging provider to push logs from SSIS processes to a custom logging service. The logging configuration is in the package level.
Process:
1. In the OpenLog, I create an operation ID to the log, to be assigned to the existing logging service.
2. When the log method is executed, I log an event in the existing logging service as a child of the operation created in the OpenLog method.
Everything works fine, however a new SSIS package was created with child packages. Therefore, now I have multiple Operation ID's, and since the packages are executed in parallel, I have to use the proper Operation ID to each log.
Problem? The Log method doesn't provide the current package. The SourceID provides the component ID, but not the Package ID.
Is there a way (from the API) to retrieve the package logging an entry?
Thanks,
Rob
So far SSIS doesn't provide a direct way to access the package name or id inside the custom log provider.
What you can do is enable the package logging through the custom log provider and provide the package name as Configuration property to custom provider.
Then you can access ConfigString property within the custom log provider methods and create an event source using it.
In your case you can create a one custom provider for both parent and child and provide different names for configuration property.