Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

SSIS Script Task

by suresh

The SSIS Script Task gives an option to implement functions that are not available or possible in the SSIS toolbox (both in built-in Tasks and transformations). The SSIS script task utilizes the Microsoft VSTA (Visual Studio Tools for Applications) as the code environment in which you can write the C# or VB Script.

TIP: SSIS Script Task VSTA provides all the standard futures available in general Visual Studio Environment.

SSIS Script Task Send Email

Drag and drop the Script Task from SSIS toolbox into the Control Flow region

SSIS Script Task 1

Before we start configuring the SSIS Script task, let us create four variables. To create a variable, right-click on the control flow region, and it will open the context menu to select the variable option. Once you choose the variable option, it will open the new window called Variables to create the new variable.

Here you can create n variables

  • EmailFrom: Please specify the Email ID from where you want to send the Email.
  • EmailTo: Please specify the Email ID to whom you want to send the Email.
  • EmailSubject: Please specify the Subject you want to include
  • EmailBody: Please specify the Message. It can be Plain Text or HTML Message
Script-Task-in-SSIS-2

Double click on the Script task will open the following editor to configure the SSIS Script task components

  • EntryPoint: Please specify the Method name that the SSIS run-time calls as the entry point. The method name you specify here must be in ScriptMain class. Remember, you can change the name as per your requirement, and when you change it you have to change it in ScriptMain class
Script Task in SSIS 3

SSIS Script Task General tab

Please click on the General tab to change the default Name and Description.

  • Name: Please provide the Unique Name
  • Description: Briefly describe the SSIS Script Task Functionality. It is always a good practice to provide a valid description.
Script Task in SSIS 4

ScriptLanguage: Microsoft provides two of its popular languages: Visual Basic (VB) and C# to use as a scripting language. I am very much familiar with C# so, I am selecting C# as my script language.

Script Task in SSIS 5
  • ReadOnlyVariables: Please select the variables that you want to use in the SSIS Script Task, and they may be user-defined variables or System default variables. Remember, variables selected as ReadOnlyVariables used for the Read-only purpose (we can’t alter them)
  • ReadWriteVariables: Please select the variables that you want to use in the Script Task, and they may be user-defined variables or System default variables. Remember, variables selected as ReadWriteVariables can alter according to our requirement

To select the variables, please click on the Eclipse (…) button ReadOnlyVariables option

Script Task in SSIS 6

Once you click on the Eclipse (…) button, Select the Variables window will open. Please select the previously created variables

Script Task in SSIS 7

Add C# code in SSIS Script Task

Once you selected the required variable, please click on the Edit Script.. button to write the actual C# Script

Script Task in SSIS 8

Once you click on the Edit Script, it will open the ScriptMain.cs class file to write the C# code.

To send an email from C# we need to add two references or import references called: using System.Net; and using System.Net.Mail;

TIP: If you are VB developer then it should be something like ScriptMain.vb

Script Task 9

Next, within the Main() function add your Code. Remember, if your code is long or robust, try to divide the code by creating methods

SSIS Script Task 10

C# code we used for this SSIS Script Task in the above screenshot is:

// C# Script for Script Task in SSIS
String SendMailFrom = Dts.Variables["EmailFrom"].Value.ToString();
String SendMailTo = Dts.Variables["EmailTo"].Value.ToString();
String SendMailSubject = Dts.Variables["EmailSubject"].Value.ToString();
String SendMailBody = Dts.Variables["EmailBody"].Value.ToString();

try
  {
     MailMessage email = new MailMessage();
     SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
     // START
     email.From = new MailAddress(SendMailFrom);
     email.To.Add(SendMailTo);
     email.Subject = SendMailSubject;
     email.Body = SendMailBody;
     //END

     SmtpServer.Port = 587;
     SmtpServer.Credentials = new System.Net.NetworkCredential(SendMailFrom, "your password");
     SmtpServer.EnableSsl = true;

     SmtpServer.Send(email);
     MessageBox.Show("Email was Successfully Sent ");
  }
catch (Exception ex)
  {
      MessageBox.Show(ex.ToString());
  }
Dts.TaskResult = (int)ScriptResults.Success;

If you forgot to create Variables (or if you find it difficult to create variables) then, you can remove the first four lines of code and replace the code between //Start… END with the below-shown code

// SSIS Script Task Example
email.From = new MailAddress("[email protected]");
email.To.Add("[email protected]");
email.Subject = "Test Mail";
email.Body = "This Email is coming from SSIS Script Task";

Once you finished editing the Script, Please close the ScriptMain.cs file and Script Task Editor. Let us run the SSIS Script Task package

SSIS Script Task 11

From the above screenshot, you can observe that SSIS Script Task is successful, and we got the message box saying that Email was Successfully sent. Let me open my Gmail

SSIS Script Task 12

From the above screenshot, you can see that we got the Email with the message we specified.

Points to Remember for this Script Task :

  • If you want to send an email to your Manager (or to yourself) after every Data Load then, you can use this SSIS Script task along with the Data Flow Task.
  • Always use the Variables for storing Emails, Passwords, Subject, or SMTP credentials.
  • If there is an Error stating Secure Connection then, Go To Less Secure Apps in your Gmail account settings and Turn on the Access for Less Secure Apps option.

Placed Under: SSIS

  • What is SSIS
  • Install SQL Server Data Tools
  • Learn SSIS in 28 Days
  • Create a SSIS Project
  • Create SSIS Package
  • SSIS Connection Manager
  • OLE DB Connection Manager
  • SSIS ADO Connection Manager
  • ADO.NET Connection Manager
  • SSIS Cache Connection Manager
  • SSIS Excel Connection Manager
  • SSIS File Connection Manager
  • SSIS FTP Connection Manager
  • SSIS SMO Connection Manager
  • Source Assistance in SSIS
  • Flat File Source in SSIS
  • OLE DB Source in SSIS
  • Excel Source in SSIS
  • ADO.NET Source in SSIS
  • SSIS FLAT FILE Destination
  • SSIS OLE DB Destination
  • SSIS ADO.NET Destination
  • SSIS Transformations
  • SSIS Audit Transformation
  • SSIS Aggregate Transformation
  • SSIS Aggregate Advanced Mode
  • SSIS Cache Transformation
  • SSIS Character Map
  • SSIS Conditional Split
  • SSIS Copy Column
  • SSIS Data Conversion
  • SSIS Derived Column
  • SSIS Export Column
  • SSIS Fuzzy Grouping
  • SSIS Fuzzy Lookup
  • SSIS Import Column
  • SSIS Lookup Introduction
  • Lookup – OLE DB Connection
  • SSIS Lookup in Full Cache Mode
  • SSIS Lookup – Case Sensitivity
  • SSIS Merge Transformation
  • SSIS Merge Join Transformation
  • SSIS Merge Join – Left Outer Join
  • SSIS Merge – Right Outer Join
  • SSIS Merge Join – Full Outer Join
  • SSIS Multicast Transformation
  • SSIS OLEDB Command
  • OLEDB Command – Delete Data
  • OLEDB Command-Update Data
  • SSIS Percentage Sampling
  • SSIS Pivot Transformation 2008
  • SSIS Pivot Transformation
  • SSIS Row Count Transformation
  • SSIS Row Sampling
  • Script Component as Source
  • Script Component as Destination
  • SSIS Script as Transformation
  • SSIS Sort Transformation
  • SSIS SCD Type 0
  • SSIS SCD Type 1
  • SSIS SCD Type 2
  • SSIS Term Lookup
  • SSIS Term Extraction Intro
  • Term Extraction – Extract Nouns
  • SSIS Extract Noun Phrases
  • Extract Nouns & Noun Phrases
  • Term Extraction – Exclusion Tab
  • SSIS Unpivot Transformation
  • SSIS Union All Transformation
  • SSIS For Loop Container
  • SSIS ForEach File Enumerator
  • SSIS ForEach SMO Enumerator
  • SSIS ForEach Variable
  • SSIS Foreach NodeList
  • Foreach ADO.NET Schema Rowset Enumerator
  • SSIS Bulk Insert Task
  • SSIS Data Profiling Task
  • Execute T-SQL Statement Task
  • SSIS Execute SQL Task Intro
  • SSIS Execute SQL Task Example
  • Execute SQL Task- Single Rowset
  • Execute SQL Task – Full Row Set
  • SSIS Execute Package Task
  • Execute Packages in SQL Server
  • Execute Packages in File System
  • SSIS Execute Package Project Reference
  • SSIS File System Task
  • SSIS File System Task- Copy Files
  • File System Task-Copy Directory
  • File System Task – Delete Files
  • File System Task – Delete Folder
  • File System Task -Move Directory
  • SSIS File System Task -Move File
  • File System – Move Multiple files
  • File System Task – Rename File
  • File System Task – Set Attributes
  • SSIS FTP TASK
  • SSIS Create Local Directory
  • SSIS Create Remote Directory
  • SSIS FTP Task Send Files
  • SSIS FTP – Send Multiple Files
  • SSIS FTP Task Delete Local Files
  • FTP TASK Delete Local Directory
  • FTP Task Delete Remote files
  • SSIS Delete Remote Directory
  • SSIS FTP Task Receive Files
  • SSIS FTP Receive Multiple Files
  • SSIS Script Task
  • Transfer SQL Server Objects Task
  • Transfer SQL Table Structures
  • Transfer SQL Tables with Data
  • Transfer SQL Stored Procedures
  • Transfer User Defined Functions
  • Transfer SQL Views in SSIS
  • SSIS Web Service Task
  • SSIS XML Task-Validate XML File
  • Transform XML File using XSLT
  • XML Task-XML files Differences
  • Create SSIS Catalog
  • Package Deployment using BIDS
  • Deploy Package Using SQL
  • Deploy using SQL Server Wizard
  • SSIS Breakpoints
  • SSIS Checkpoints
  • SSIS Error Handling
  • SSIS Event Handlers
  • SSIS Transactions
  • SSIS Logging
  • SSIS Parameters
  • SSIS Package Configuration
  • Configure using SQL Server
  • Config using Registry Entry
  • Conf with Environment Variable
  • SSIS XML Configuration File
  • XML Configuration File Part 2
  • SSIS Package Protection Level
  • SSIS Incremental Load
  • Incremental Load Example 2
  • SSIS Remove Double Quotes
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy