[转]SSIS Recordset Destination
本文转自:http://www.sqlis.com/sqlis/post/Shredding-a-Recordset.aspx
Doing what to a recordset?
Shredding a recordset in this instance means that we are going to show you how to take a recordset produced in your SSIS package, loop over the rows in that recordset, break apart the columns and do something with them. This is really useful when you want to preform an action on a row of data for every row of data just like we are going to do here. Sure we could use an ExecuteSQL task to get the recordset as well but that does limit our choices of source data whereas doing it in the pipeline does not. Something useful we hope.
Retrieving the Recordset
There are a couple of things that we are going to have to setup first though
The Variables
This task requires four variables. It needs one to hold the recordset and 3 to hold the column values when we shred the recordset. Let's configure those now. In control flow we have a menu titled SSIS and if we drop that down we see Variables as one of the menu choices. Here is how the variables look after completion
The Connections
For this package we are going to need two connections. One for the source data and one for the SMTP server with which we are going to send our mails.
To set up an OLE DB Connection Manager we will right click in the Connection Manager tray at the bottom of our package and choose New OLE DB Connection
We click New and configure as seen in the graphic.
Click OK after doing that and let's create the SMTP connection manager. Same drill as before, right click in the Connection Manager tray only this time we choose New Connection. That brings us to the following screen where we now choose the SMTP Connection as shown.
We then have to configure the connection manager and luckily it is one of, if not the, most easy to set up of all.
If you look in the Connection Manager tray now you should see something very similar to the following
The DataFlow Task
This task in this example is about one thing and that is getting the data we want into a variable so we can use it later in the package. We are going to need to fill our recordset with something so we will need to define a statement that retrieves our rows. Imagine we have sales people who take contact details from potential customers. They must contact those people within 30 days and update our CRM system. If they do not then we want to let them know through eMail that they are overdue.
So now we have something to put into a recordset let's build the means by which we can get the data. Begin by adding a Data Flow task to the Control Flow. Double click on the task to enter the Data Flow section of our package. Now drag from the toolbox onto the design surface the following:
- An OLE DB Source
- A Recordset Destination
The first thing we are going to do is configure the OLE DB Source so we double click on it to open up its editor
In here we are going to specify the connection manager built earlier, an Access Mode of SQL Command and a SQL command text. The graphic above shows this completed
If we look to the left of this editor we can see a columns branch on the tree underneath the connection manager branch. This is where we need to tell the source what columns from our statement we want to flow down the pipeline so we click on that now and request that all columns be sent.
Now we need to configure the recordset destination. Before we do that we drag the green connection coming from the OLE DB source and simply attach it to the recordset destination. This will give the destination the ability to know what to expect in terms of structure. After attaching the connector we double click on the recordset destination.
The thing to see on this page is the VariableName property to which we give the name of the variable in which we want to store the recordset (rsDetails).
Just like we did on the source we need to configure some columns and we do that by clicking on the Input Columns tab. We want to write all columns to the destination so we select all the available columns.
When we now come out of the destination editor our Data Flow looks like this.
Breaking It Apart
We have seperated this part of setup because it is logically distinct from the previous phase. This is where we are going to grab the recordset, break it apart and use the values we get from breaking it apart and do something with them.
The ForEach Container
The ForEach Loop container allows us to loop over a collection of objects. We can, using this container, loop over a number of inbuilt collections but in this article we are in interested in only one of the collections, the ADO Enumerator. When the enumerator loops over the collection it returns at most one instance of the collection on each iteration. That object needs to be passed out to the tasks inside the container and we do that through a variable. In this article we use the variable User::rsDetails. We drop a ForEach Loop container onto designer from the toolbox. After double clicking on it we choose from the tree on the left Collection. The following graphic shows our collection chosen and variable assigned.
So what happens then? Well on each iteration of the loop a row from the recordset is assigned to the variable with in our case three columns. We now need to Shred it. We now click on the Variable Mappings item in the tree. The following graphic shows our variables configured to accept the columns in the recordset.
What''s happening here is that the variables on the left that we configured earlier are being assigned to the column indexes, on the right, in the recordset and they are zero based. We have no expressions to configure so that''s it for this task. Right so we have our columns in the row mapped to variables and we need to do something with them. That comes now with the Send Mail Task
The Send Mail Task With Expressions
This does as the name suggests and for us this is the way that we are going to communicate to our employees that they have not followed up on their leads. Remember the SMTP Connection Manager we configured earlier well this where we are going to use it. Drop a Send Mail task onto the designer and place it inside the ForEach Loop container.
We double click on the task and after configuration it looks now like this.
We haven't configured all the properties we need because we are going to use property expressions to do that in a moment so we click on Expressions in the tree on the left.
As you can from the graphic above there are ellipses to the right and we need to click on them now. The window we now see is where we will choose a property on the left hand side of the window and then assign an expression on the right. Again we see here ellipses and this will take us to a great expression editor for the property. The window is shown below.
The thing about property expressions is that they are evaluated at runtime. We can build quite complex expressions to map to our properties. In this article we need three properties to be dynamic and part of the expressions will be the variables we grabbed earlier. The properties we need to configure are:
- Message Source
- ToLine
- Subject
The following three graphics show these properties in the expression editor with their expressions set.
The Message Source
One thing to note about this window is that we have pressed the Evaluate Expression button and as you can see our expression is evaluated and displayed. This gives you an idea of what it ill look like when this happens at runtime
The ToLine
The Subject
Now with all our expressions set the expressions window looks like this
That''s it for expressions so the last thing we need to do is join the green connector from the Data Flow Task onto the Foreach Loop Container and we''re done.
Summary
This article has demonstrated a number of new things in SSIS and we hope you have found it useful. Be sure to let us know if you think the Recordset Enumerator is useful and any interesting uses to which you may put it.
[转]SSIS Recordset Destination的更多相关文章
- SSIS ->> Excel Destination无法接受大于255个字符长度的字符字段(转载)
从下文的链接中找到一些背景,因为Excel会以前8行作为参考,如果某个字段前8行的最长长度没有超过255个字符,就会报错.如果知道某个字段属于描述性字段,而且字段的数据长度很可能超过255个字符长度, ...
- SSIS ->> Excel Destination无法接受大于255个字符长度的字符字段
从下文的链接中找到一些背景,因为Excel会以前8行作为参考,如果某个字段前8行的最长长度没有超过255个字符,就会报错.如果知道某个字段属于描述性字段,而且字段的数据长度很可能超过255个字符长度, ...
- BI之SSIS入门最新版Visual Studio调试技巧
简介 最近公司业务需要用到BI SSIS,SSIS是什么?"SSIS是Microsoft SQL Server Integration Services的简称,是生成高性能数据集成解决方案( ...
- SSIS:控件清单
Control Flow 控制流程 Containers 容器 For Loop Container Foreach Loop Container Sequence Container Core Ta ...
- SSIS Destination 组件使用Fast-Load mode出错
查看一个Package的历史Message 数据,发现 DataFlow Task 经常出错,错误信息的Description是: Description: "While reading c ...
- 微软BI 之SSIS 系列 - 使用 Script Component Destination 和 ADO.NET 解析不规则文件并插入数据
开篇介绍 这一篇文章是 微软BI 之SSIS 系列 - 带有 Header 和 Trailer 的不规则的平面文件输出处理技巧 的续篇,在上篇文章中介绍到了对于这种不规则文件输出的处理方式.比如下图中 ...
- [转]Insert, Update, and Delete Destination table with SSIS
本文转自:http://www.rad.pasfu.com/index.php?/archives/150-Insert,-Update,-and-Delete-Destination-table-w ...
- ssis error at other ssis.pipeline "ole db destination" failed validation and returned validation status
我在修改一个ssis的包,发现这个destination的表被改过了.所以就重建了表.就导致了这个错误. 打开包重新检查下表结构的匹配就好了
- SSIS 处理NULL
不同于SQL Server中NULL表示值是未知的(Unknown Value),没有数据类型,但是,在SSIS中,NULL是有数据类型的,要获取某一个NULL值,必须指定数据类型,例如,变量 Int ...
随机推荐
- springmvc3 拦截器,过滤ajax请求,判断用户登录,拦截规则设置
web.xml设置:(/拦截所有请求) <servlet> <servlet-name>dispatcher</servlet-name> <servlet- ...
- php之trait-实现多继承
PHP是单继承的语言,在PHP 5.4 Traits出现之前,PHP的类无法同时从两个基类继承属性或方法.php的Traits和Go语言的组合功能类似,通过在类中使用use关键字声明要组合的Trait ...
- 解决Tomcat因Redis加载慢而启动失败的问题
StartTomcat.py import subprocess as t import time, os, requests, sys WEB_IP = '127.0.0.1:8080' # WEB ...
- 关于在C#中对函数重载理解
函数重载是个什么概念,才接触的这个概念的时候我也是完全昏了,还在自己看看了书后就理解了.那什么是函数重载呢?我个人理解的是在同一个作用域下有多个同名的函数,但是他们的形参的类型是不同的,或者参数个数是 ...
- NHibernate框架与BLL+DAL+Model+Controller+UI 多层架构十分相似--『Spring.NET+NHibernate+泛型』概述、知识准备及介绍(一)
原文://http://blog.csdn.net/wb09100310/article/details/47271555 1. 概述 搭建了Spring.NET+NHibernate的一个数据查询系 ...
- 解决 .htaccess 导致的403禁止访问
如果启用了mod_rewrite, 那么Options就一定要启用FollowSymLinks或者SymLinksifOwnerMatch, 否则会出现Fobidden页面禁止访问的错误. 于是把 O ...
- python No migrations to apply
错误显示: “No migrations to apply” 错误情况:python在通过model同步数据库时,提示 No migrations to apply 查看数据库,新表没有被创建,只是 ...
- 【Shell】一些比较有用、常用的shell命令
最近帮着老大做一些服务器上的日志处理任务,小弟之前只是稍微会用点Linux,但是一些高级的命令基本不会,经过一番折腾,总结了几个自认为比较有用的命令,之后学到更多的再来补充. 一.文本处理:awk 二 ...
- SSL压力测试工具THC-SSL-DOS
SSL压力测试工具THC-SSL-DOS SSL广泛应用安全加密和认证领域,如HTTPS.POP等服务.使用SSL,会加重服务器的负担.例如,在协商阶段,服务器的CPU开销是客户端的15倍.Kal ...
- Mixins 改成使用高阶组件调用
把组件放在另外一个组件的 render 方法里面, 并且利用了 {...this.props} {...this.state} 这些 JSX 展开属性 对比下2种代码: 原始方式: <!DOC ...