[转]Getting started with SSIS - Part 10: Event Handling and Logging
Let us now add some more features to our package. We would now add Event handling and Logging to our package created. Before doing that, let us see what do the two means.
Event Handling: As the name suggests, based on certain event, we would like to take some action (handle the event) the way we want. We may want to shoot an email in case of an error or failure in the package. Or we might want to truncate a table once the ETL is completed.
Logging: Again, as the name suggests, we need to log the events that are happening in our package. For example, we need to know which all tasks have executed successfully or have failed. In case of failure, what was the error message etc.
The difference between the two is that in Logging, we merely record the events and any message generated by the system to a log file, table etc. While in case of Event Handling, we may wish to take additional action based on the events.
Having said this, we shall start the demo on Event Handling in SSIS.
We will go back to our package created earlier. It has just a data flow task to move the data from Flat file to a database table. What we will do is to introduce an error in the package and then handle the event in a way we want.
Here, we have the package ready and the data flow task as mentioned above (see image below). Please look along and do as explained along with the images.
In the above Data Flow Task, we have just a Flat File Source and an OLEDB Destination (see the image below).
Now we start with the Event Handling. Take a look at the figure below. You will notice we have now moved to a new tab Event Handlers. You will see two dropdown boxes, one stating Executable and other stating Event Handler.
Click on the 2 dropdowns and you would see the values as in the figure below. Executables are all the tasks that you see on the Control Flow. While Events are the possible events that can happen on the above executables. I select the Data Flow task in the Executable and for handling I will select OnError event.
Once we make the above selection, we will see the screen below:
Click on the hyperlink and the screen would look like the one in the figure below:
The point to be noted is that we can have all the tasks that we have in Control Flow in the event handler. We can have a kind of small package here, which does its own ETL. Event handlers are very powerful and useful tool available to the SSIS developers.
We have selected the task as Data Flow Task and the event we want to handle is onError. This means that when an error will occur this event will be fired and what task we drop in the above area (as in the figure above) will be executed if the Data Flow task fails.
To achieve this we need to introduce an error in the package. All you need to do to achieve this is to open the flat file connection we have and change the file name to a non-existing name. Now when the package executes, it will not find the file and the package will fail. Now, what we want is whenever this happens or other error occurs, an entry per error should be recorded in a log table we have.
Use the query below to create the log table
CREATE TABLE [dbo].[Log](
[ID] [int] IDENTITY(1,1) NOT NULL,
[PackageID] [uniqueidentifier] NULL,
[Error] [nvarchar](max) NULL,
[Source] [nvarchar](100) NULL,
[PackageName] [nvarchar](100) NULL
) ON [PRIMARY]
Let is now get back to our package.
Double click the Execute SQL Task to open the Editor window as in figure below
Set up the Connection String and use the below Insert Query in the SQL Statement.
INSERT INTO [dbo].[Log]
([PackageID]
,[Error]
,[Source]
,[PackageName])
VALUES
(?,?,?,?)
The question marks used above are the parameters we pass to the above query. Based on the mapping we do in the next step, these will get the value.
Next, go to the Parameter Mapping tab as shown in the next figure. I will not the talking on all the details you see on this tab. We will cover it in later section. As of now, I would ask you to set up your Parameter Mapping exactly as you see here. One point to note here is that we are using the system variables and not user variables to map the values for the parameters. Here you will see how useful the system variables are. Once you have set up parameter mapping, click OK. You are done.
Now execute the package by clicking F5. You will see that the package fails and the Data Flow Task goes red (see figure below). If this does not happen and the package is executed successfully, ensure that you have changed the name of the file in the flat file connection manager to a non-existent file name.
If you double click the Data Flow Task, you will notice that the Flat file Source has failed. I hope you know the reason.
If you now go to the Event Handler tab, you will notice that the Execute SQL Task that we had put here has executed successfully.
Go to the Data base where you created the Log table and select the records from the log table.
SELECT * FROM LOG
You should the following output:
Now instead of the execute SQL task, you could have a send mail task to notify the admin etc.
LOGGING
We will now see how to implement logging in SSIS Packages. This is rather simple to implement.
Go to the SSIS Menu and select logging from there.
We have various options to save the SSIS Logging (see figure below). We can save the logs to Windows Event log, a Text File, XML File, SQL Server Table or SQL Profiler. The choice is yours, choose the one you feel perfect for your need. I will use SQL Server Table as the provider. Select the Provider as SQL Server and click the Add button next to it.
Select the SQL Connection where you want to log the events. I will use the same Database Connection I used in the Data Flow Task. You can have separate database for logging as practiced in real life scenarios. Also, check the checkbox on the left side else, the logging will not occur. You need to do the log for the entire package; you could select the executable for which you want to enable to logging. I have selected the entire package for logging.
Once you are done with the above setting, go to the Details tab. Here, you will see the various events that you have for each executable. Select the events you wish to log. Generally we log the following events:
- OnValidate
- OnPreExecute
- OnWarning
- OnError
- OnPostExecute
We are done!! Execute the package, go to the data base that you configured for logging above and fire this query:
SELECT * FROM dbo.sysssislog
This table is automatically created, you can change the table name but that will be shown in later articles. Check the output you get for the above.
In the next article we will take a look at the various ways to execute a package.
[转]Getting started with SSIS - Part 10: Event Handling and Logging的更多相关文章
- 理解iOS Event Handling
写在前面 最近的一个iOS App项目中遇到了这么问题:通过App访问服务器的大多数资源不需要登录,但是访问某些资源是需要用户提供验证的,一般来说,通常App的做法(譬如美团App)将这些资源放在“我 ...
- Event Handling Guide for iOS(五)
基本概念: 加速计: 又称加速度计,测量设备运动的加速度. 加速度: 矢量,描绘速度的方向和大小变化的快慢. 陀螺仪: 感测与维持方向的装置. 原文: Motion Event声明: 由于本人水平有限 ...
- Event Handling in Spring
Spring内置的event有 1.ContextRefreshedEvent This event is published when the ApplicationContext is eithe ...
- Console Event Handling
http://www.codeproject.com/Articles/2357/Console-Event-Handling Console Event Handling Kumar Gaurav ...
- Event Handling Guide for iOS--(三)---Event Delivery: The Responder Chain
Event Delivery: The Responder Chain 事件传递:响应链 When you design your app, it’s likely that you want to ...
- Event Handling Guide for iOS--(二)---Gesture Recognizers
Gesture Recognizers 手势识别器 Gesture recognizers convert low-level event handling code into higher-leve ...
- Event Handling Guide for iOS--(一)--About Events in iOS
About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...
- UI Framework-1: Aura Event Handling
Event Handling A diagram of the architecture of this system: HWNDMessageHandler owns the WNDPROC ...
- Event Handling Guide for iOS--事件驱动指南
事件是发送给应用程序来通知它用户动作的对象.在iOS中,事件可以有多种形式:多触摸事件,motion(,移动,手 势)事件---例如,设备的加速计(accelerometer)--和控制多媒体的事件. ...
随机推荐
- linux命令(46):chgrp命令
在lunix系统里,文件或目录的权限的掌控以拥有者及所诉群组来管理.可以使用chgrp指令取变更文件与目录所属群组,这种方式采用群组名称或群组识别码都可以.Chgrp命令就是change group的 ...
- 当你用element-ui遇到需要在el-table-column上v-for时,这篇文章你能用的上,也就是你需要二级循环
好链接就要丢过去 https://blog.csdn.net/qq_28929589/article/details/79445354
- js字符串与Unicode编码互相转换
).toString() "597d" 这段代码的意思是,把字符'好'转化成Unicode编码,toString()就是把字符转化成16进制了 看看charCodeAt()是怎么个 ...
- Find Peak Element——二分查找的变形
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up
http://mail-archives.apache.org/mod_mbox/cloudstack-users/201306.mbox/%3c201306181058330006472@gmail ...
- CSS Modules入门及React中实践(内附webpack4配置)
本篇文章以整理为主,自己进行了部分修改,如有侵权,请告知 CSS Modules介绍 CSS Modules是什么东西呢?首先,让我们从官方文档入手:GitHub – css-modules/css- ...
- Nginx的基本理论
Nginx是什么? 1).Nginx 就是一台反向代理服务器,代理服务器一般是指局域网内部的机器通过代理服务发送请求到互联网上的服务器,代理服务器一般作用于客户端.比如GoAgent,FQ神器. 一个 ...
- Java基础:类加载机制
之前的<java基础:内存模型>当中,我们大体了解了在java当中,不同类型的信息,都存放于java当中哪个部位当中,那么有了对于堆.栈.方法区.的基本理解以后,今天我们来好好剖析一下,j ...
- mvc controller放目录里面该怎么办?
方法一,可以在目录中命名一个和目录同样名字的controller,然后用特性来进行设置,比如: Controllers/myfolder/myfolderController.cs 我建立了上述结构, ...
- 【ASP.NET】IHttpHandler和IHttpModule
上篇文章我们主要讲了HttpApplicatiion管道事件,那么我么如何处理这些管道事件呢,以及请求在ASP.NET是如何执行的呢,我们来了解一下IHttpHandler和IHttpModule 引 ...