9012 Views
4 minutes read
Categories
Microsoft 365

Retrieve Records in SSIS Script Task

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.

r1

Steps

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

Click on SQL Server Data Tools

r2

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

Click on Project

r3

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

r4

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

r5

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

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

r7

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

r8

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

XAML 4
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

r10

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

r11

11. Click on Add Variable

r12

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

r13

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

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

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.

r16

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

r17

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

r18

18. Now select the Table Name

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.

r20

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

r21

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

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).

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.

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.

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.

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

r27
LinkedinTwitterFacebook

1 reply on “Retrieve Records in SSIS Script Task”

Leave a Reply

Your email address will not be published. Required fields are marked *