Quantcast
Viewing all articles
Browse latest Browse all 2

Retrieve Records in SSIS Script Task

Overview

You are developing an SSIS package. You want to work with a record in a Script Task. This blog discusses how you can get access to the Records in the Script task using the Object Type variable.

Image may be NSFW.
Clik here to view.
r1

Steps

1. Go to Start >>All Programs>> Microsoft SQL Server 2012>>

Click on SQL Server Data Tools

Image may be NSFW.
Clik here to view.
r2

2. Visual Studio >> File >>New >>

Click on Project

Image may be NSFW.
Clik here to view.
r3

3. Select Business Intelligence Under Installed Templates >>Integration Service Project
Click Ok Button

Image may be NSFW.
Clik here to view.
r4

4. Now you can see inside Visual studio >> solution Explorer >> Package.dtsx

Image may be NSFW.
Clik here to view.
r5

5. Double click on Package.dtsx file and you can see the design editor of that package

Image may be NSFW.
Clik here to view.
r6

6. Now go to the SSIS tool box  and add (either drag and drop or double click) a Data flow task controls inside the control Flow Tab

Image may be NSFW.
Clik here to view.
r7

7. Add another control script Task from SSIS toolbox to Control flow tab

Image may be NSFW.
Clik here to view.
r8

8. Create a connection between Data Flow Task and Script Task using the down side arrow of Data Flow Task

Image may be NSFW.
Clik here to view.
XAML 4
Image may be NSFW.
Clik here to view.
r9

9. Now we need to add an object type variable, so go to the right most side of the Package Design Editor and click on Variables

Image may be NSFW.
Clik here to view.
r10

10. It will open a Window, Bottom side of your visual studio

Image may be NSFW.
Clik here to view.
r11

11. Click on Add Variable

Image may be NSFW.
Clik here to view.
r12

12. Give a Name to the variable and Select Data type as Object 

Image may be NSFW.
Clik here to view.
r13

13. Double click on Data Flow Task this will bring you data flow tab

Image may be NSFW.
Clik here to view.
r14

14. We can use any kind of data source like Flat File Source, Excel Source, OleDb Source etc. I have Used OleDB Source, as per project requirement.

So just drag and drop the OleDB source control from SSIS tool box to Data Flow Tab

Image may be NSFW.
Clik here to view.
r15

15. Double Click on OleDB Source control and we will get the oleDB Source editor.

Inside the Connection Manager we have to set the OleDB connection Manager.

Image may be NSFW.
Clik here to view.
r16

16. Click on the New button and we will get the Configuration ole DB Connection Manager Window

Image may be NSFW.
Clik here to view.
r17

17. Again, Click New button, put the server Name and Select the database Name in the Connection manager window and click ok.

Image may be NSFW.
Clik here to view.
r18

18. Now select the Table Name

Image may be NSFW.
Clik here to view.
r19

19. We can choose selected columns from the selected table, just go to the columns tab and unselect the checkbox beside the column and click ok.

Image may be NSFW.
Clik here to view.
r20

20. Add another control into the Data Flow Tab called Record set destination

Image may be NSFW.
Clik here to view.
r21

21. Connect the Ole DB source with Record set Destination using the bottom side of Ole Db source control.

Image may be NSFW.
Clik here to view.
r22

22. Double click on the Record set Destination , we’ll get the Advance editor for record set destination, inside the component properties tab there is a custom property called Variable Name.  Select the object type variable (that we have previously created).

Image may be NSFW.
Clik here to view.
r23

23. Go to the next tab called Input columns and choose the columns as per your requirement, also we can set the usage type whether the columns are read only or read write type. After all required settings click OK.

Image may be NSFW.
Clik here to view.
r24

24. Go to the control flow tab back and double click on the Script Task control. And set the Object type variable that we had created as Read Write variables.

Image may be NSFW.
Clik here to view.
r25

25. Click on the Edit Script Button , this will open another project called Vista Project, Inside that project ScriptMain.cs is the class file, where we have to add some codes to access the Object type variable that we have passed from our SSIS package.

Image may be NSFW.
Clik here to view.
r26

26. We’ll add a namespace for ole DB data adapter using System.Data.OleDb;

And add some lines of code inside the main method or any other sub method

OleDbDataAdapter da = new OleDbDataAdapter();

DataTable dt = new DataTable();

da.Fill(dt, Dts.Variables[0].Value);

27.  Finally we can get all the records passed from our SSIS package inside the data table object.

Output

Image may be NSFW.
Clik here to view.
r27


Viewing all articles
Browse latest Browse all 2

Trending Articles