blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

SSIS Junkie

Conchango are busy and need top level Technical Architects for Microsoft & Open Source platforms in and around London. Interested? Email me or send me a message

SSIS: Accessing a recordset in a script task

UPDATE 2006-03-14: This information in this post should now be disregarded. Read here: http://blogs.conchango.com/jamiethomson/archive/2006/01/04/2540.aspx instead!

It is possible to populate an SSIS variable of type "Object" with a recordset using the "Recordset Destination" data flow destination component. Thereafter there are various ways to access the contents of this recordset, one of which is to use a Foreach loop to loop over the recordset (using the "For each ADO Enumerator") and then use a Script Task to access the enumerated record.

The record can be exposed in the script task as an ADODB.Fields object. The following code shows how to access the various values in the record:

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

    Public Sub Main()

    Dim vars As Variables

    Dim fields As ADODB.Fields

    Dts.VariableDispenser.LockOneForRead("vRecord", vars)

    fields = CType(vars(0).Value, ADODB.Fields)

    MsgBox(fields(0).Value.ToString() + " - " + fields(1).Value.ToString())

    Dts.TaskResult = Dts.Results.Success

  End Sub

End Class

HOWEVER...there is a caveat here. The ADODB namespace cannot be accessed straightaway using the off-the-shelf installation. Follow these steps in order to make the ADODB namespace accessibe to your scripts:

  1.. Copy %Program Files%\Microsoft SQL Server\90\Tools\bin\adodb.dll to %windir%\Microsoft.net\framework\v2.0.xxxxx
  2.. In the script task script editor (Visual Studio for Applications) go Projects-->Add Reference and add adodb

Personally I think this namespace should be accessible without all this messing about, it should be installed into the correct location. So to the SSIS dev team....can the installation be changed to install this DLL (and maybe many others) into the correct place in order for it to be used?

- Jamie

N.B. I've got a demo package for all of this but we're having problems with our blog site at the mo which means I can't upload files at the moment. If you want the demo package sending to you post a comment up here with your email address and I'll send it to you!

UPDATE:

Kirk says there is functionality coming in IDW14 that means all of this messing about with DLLs won't be necassary. Great news! Read about it here!

Published 08 February 2005 23:13 by jamie.thomson

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

TrackBack said:

DatabaseDaily.com
February 14, 2005 08:54
 

Samir Mitra said:

Hi Jamie,

I would like to know as to how do I access the data in an in memory recordset in SSIS 2005. I basically wish to loop through the recordset and use the resultant output in each loop in an sql query to check whether that field data already exists in an SQL server db table field.

It would be great if you could send me a copy of the demo package.

Thanks,
Samir.
March 16, 2006 11:24
 

Vladimir Kievsky said:

Appreciate you showing internals of SSIS script programming. Many words are spent in Internet-based articles without showing the depth of the subject useful in real apps.

March 21, 2007 16:57
 

Wai-Fong Chow said:

I like to see how to execute a SQL task in Script task (SSIS).  I would like to see your demo package.  Can you email to wchow@event360.com?

Thank you.

Wai

April 24, 2007 08:44
 

George Thomas said:

Could you please email me the demo package as well?  My email is gnanduru@rocketmail.com.  Many Thanks.

June 5, 2007 19:42
 

jamie.thomson said:

Hello George,

As you will see above, the information presented here should now be disregarded. Please follow this link http://blogs.conchango.com/jamiethomson/archive/2006/01/04/2540.aspx.

-Jamie

June 5, 2007 20:03
 

anish said:

Could you please email me the demo package..  My email is anish.francis@sryas.com. Thanks..

November 23, 2007 04:02
 

AMBAREESH P S said:

Hi

Please could you send me the package to ps.ambareesh@yahoo.com

Regards

AMBAREESH

November 28, 2007 06:14
 

Rashmi Motiwale said:

Please send the demo for the above exercise at rashmim@hexaware.com

February 25, 2008 09:04
 

surya Prakash said:

The path of adodb.dll -

c:\Windows\Microsoft.Net\Framework\V2.0.50727\adodb.dll

Thanks

Surya Prakash

February 27, 2008 06:31
 

Surya Prakash said:

The Path of adodb.dll is

C:\Program Files\Microsoft.NET\Primary Interop Assemblies-ADODB.dll-

and copy to c:\Windows\Microsoft.Net\Framework\V2.0.50727\

and go to Script Task  Projet Explorer -Add Reference You will find this dll

Thanks

Surya Prakash

February 29, 2008 07:13
 

Kaoru said:

Hi,

I copy the file adodb.dll, but there isn't a ADODB.Fields. What should I do?

thanks

Kaoru

July 1, 2008 17:45
 

jamie.thomson said:

Kaoru (and others),

Please note the link right at the top of this page. The information herein should now be disregarded.

-Jamie

July 2, 2008 09:56

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

Powered by Community Server (Personal Edition), by Telligent Systems