
After completing this course, you will be able to create a simple notification solution to deliver messages, alerts, updates or reminders to users across different platforms and devices.
Real Word Project
Equipped with hands-on activities
Live Demo for you to follow along
Learn from scratch, step by step on how to create a simple package and automating to run the package on a planned schedule
If you are still struggling to follow along, don’t worry. I have shared all the codes for you to copy and paste
After completing this course, you can use this project in your resume to catch employer’s attention or you can start your own business as side gig.
You will learn the following on this course:
Sending notifications through email
Sending text message alerts to phone number
Using variables, Row Count, Recordset Destination, Script Task, Foreach Loop
Sending an attachment to the email
Export data from the database and importing it to a flat time.
Updating subject line in real time.
Querying data from the database and writing it to the email body
What do you need in order to send a notification?
Simple Mail Transfer Protocol (SMTP) server
SMTP Port Number
587
From – Specifies the email address of the sender which may be used by recipient of the mail to reply back.
Password – Specifies the password of the sender
To – Provides the email address of the recipients, multiple recipients emails are separated with semicolons.
Subject – Provides a subject/heading of sender’s email.
Body – Where the sender writes their main message. Including the text, images, links etc.
Scrip Task Component
The Script Task in SQL Server Integration Services (SSIS) allows you to add custom code using languages like C# or VB.NET to perform specific tasks that aren't readily achievable using built-in SSIS components. Here's a comprehensive guide on using the Script Task in SSIS:
1. Adding a Script Task:
- Drag and drop a Script Task from the SSIS Toolbox onto the Control Flow design surface in your SSIS package.
2. Configuring the Script Task:
- Double-click the Script Task to open the Script Task Editor.
- Click on "Edit Script" to open the script editor in the selected language (C# or VB.NET).
3. Writing Code:
- Write your custom code within the script editor. You can use .NET Framework classes and assemblies to perform various tasks.
- The script editor provides access to SSIS variables, connections, and other objects through the `Dts` object. For example:
- Access SSIS variables using `Dts.Variables["VariableName"].Value`.
- Access SSIS connection managers using `Dts.Connections["ConnectionManagerName"].ConnectionString`.
- Log messages using `Dts.Events.FireInformation`.
4. Accessing SSIS Package Properties:
- You can access properties of the SSIS package using the `Dts` object. For example:
- `Dts.Variables["$Package::PackageName"].Value` to access the package name.
- `Dts.Variables["$Package::PackageDescription"].Value` to access the package description.
- `Dts.Variables["$Package::CreatorName"].Value` to access the creator's name.
5. Adding References:
- If your script requires additional assemblies or libraries, you can add references to them by right-clicking on the project in the Solution Explorer, selecting "Add Reference", and browsing for the required DLLs.
6. Debugging:
- Debugging a Script Task can be done using breakpoints and debugging tools provided by the script editor. You can set breakpoints by clicking on the left margin of the code window.
7. Error Handling:
- Implement error handling within the script task to handle exceptions gracefully. You can use try-catch blocks to catch exceptions and handle them accordingly.
8. Testing and Execution:
- Test the Script Task by running the SSIS package. Verify that the custom code executes as expected and performs the desired tasks.
9. Logging:
- Log relevant information or errors generated by the Script Task using SSIS logging features. You can log to various destinations such as text files, SQL Server databases, or Windows Event Log.
10. Best Practices:
- Keep the script code simple, well-commented, and organized.
- Avoid using script tasks for tasks that can be achieved using built-in SSIS components.
- Test thoroughly and ensure that the script performs efficiently, especially for large datasets or complex logic.
The Script Task in SSIS provides a powerful way to extend the functionality of your SSIS packages and accomplish tasks that are not possible with built-in components alone. However, it should be used judiciously and only when necessary, as excessive use of script tasks can make packages harder to maintain and debug.
Short Messaging Service (SMS) and Multimedia Messaging Service (MMS) Gateway
You must know your recipient’s carrier to select the correct email to SMS address.
Limited to 160 characters. Longer messages maybe truncated or a recipient may receive multiple messages,.
Use MMS if the message is longer than 160 characters, a video or an image.
T-Mobile: number@tmomail.net (SMS and MMS)
AT&T: number@txt.att.net (SMS); number@mms.att.net (MMS)
Verizon: number@vtext.net (SMS); number@vzwpix.net (MMS)
Sprint: number@messaging.sprintpcs.com (SMS); number@pm.sprint.com (MMS)
Cricket: number@sms.cricketwireless.net (SMS); number@mms. cricketwireless.net (MMS)
Subject – Provides a subject/heading of sender’s email.
Body – Where the sender writes their main message. Including the text, images, links etc.
Carbon Copy (CC) – Specifies email address of the individuals who receive copies of the email.
Blind Carbon Copy (BCC) – Specifies email address of the individuals who receive blind carbon copies of the email.
Priority (Low, Normal, High) – Sets the priority of the email.
Attachment – Provides the path and file name of the attachment to the email.
SSIS variables are used to store values that can be used throughout your SSIS package. They provide a way to dynamically control and manipulate data, connections, and control flow elements. Here's a breakdown of SSIS variables and how they're commonly used:
1. Types of Variables:
- System Variables: These are built-in variables provided by SSIS, such as `PackageID`, `PackageName`, `ExecutionInstanceGUID`, etc. They provide information about the package and its execution.
- User Variables: These are variables created by users within the SSIS package. User variables can be used to store values such as connection strings, file paths, query parameters, or any other data needed during package execution.
2. Scope:
- Variables can have different scopes within an SSIS package. The scope determines where the variable is accessible and how long its value persists.
- Scopes can be at the package level, container level (e.g., Sequence Container, For Loop Container), or task level (e.g., Data Flow Task, Execute SQL Task).
3. Usage:
- Variables can be used in various ways within SSIS:
- Expressions: Variables can be used in expressions to dynamically set properties of SSIS components.
- Script Tasks: Variables can be accessed and manipulated within Script Tasks using code written in languages such as C# or VB.NET.
- Control Flow Logic: Variables can control the flow of execution within the package by influencing the behavior of precedence constraints or the outcome of conditional split transformations.
- Data Flow Tasks: Variables can be used to pass data between Data Flow Tasks or to configure components within Data Flow Tasks.
4. Variable Data Types:
- SSIS variables support various data types such as string, integer, boolean, date/time, and object. Choose the appropriate data type based on the type of data you intend to store in the variable.
5. Parameterization:
- Variables can be used for parameterization, allowing you to make your SSIS packages more dynamic and configurable. For example, you can use variables to parameterize connection strings, file paths, SQL queries, or package configurations.
6. Variable Configurations:
- SSIS variables can be configured to have static values or to be populated dynamically at runtime. You can use expressions, script tasks, or package configurations to set variable values dynamically.
7. Debugging and Logging:
- Variables can be monitored during package execution for debugging purposes. SSIS provides logging capabilities that allow you to capture variable values at different points in the package execution for troubleshooting and auditing.
SSIS variables are fundamental to building flexible, dynamic, and reusable SSIS packages. They enable you to create robust ETL solutions that can adapt to changing requirements and environments. Understanding how to effectively use variables is key to mastering SSIS development.
In SSIS, using variables inside a Script Task allows you to access and manipulate those variables programmatically using C# or VB.NET code. This capability provides flexibility and allows you to perform custom logic or calculations based on the values stored in the variables. Here's a basic guide on how to use variables inside a Script Task:
1. Add a Script Task:
- Drag and drop a Script Task from the SSIS Toolbox onto the Control Flow design surface.
2. Edit the Script Task:
- Double-click the Script Task to open the Script Task Editor.
- Click on "Edit Script" to open the Visual Studio for Applications (VSA) environment.
3. Accessing Variables:
- Once inside the Script Task editor, you can access SSIS variables using the `Dts.Variables` collection.
- Variables are accessed using their names, and you can read or write their values as needed.
4. Example in C#:
- Here's an example in C# demonstrating how to access and use variables inside a Script Task:
----------------------------------c#--------------------------------------------------
public void Main()
{
// Accessing variables
string myStringVariable = (string)Dts.Variables["User::MyStringVariable"].Value;
int myIntVariable = (int)Dts.Variables["User::MyIntVariable"].Value;
// Manipulating variables
myStringVariable += " appended text";
myIntVariable *= 2;
// Updating variables
Dts.Variables["User::MyStringVariable"].Value = myStringVariable;
Dts.Variables["User::MyIntVariable"].Value = myIntVariable;
Dts.TaskResult = (int)ScriptResults.Success;
}
-------------------------------------------------------------------------------------
5. Error Handling:
- Ensure that you handle any potential errors that may occur while accessing or manipulating variables within the Script Task.
- You can use try-catch blocks or other error handling techniques to gracefully handle exceptions.
6. Testing and Execution:
- Test the Script Task by running the SSIS package and verify that the variables are accessed and manipulated correctly.
Using variables inside a Script Task gives you the flexibility to customize your SSIS package logic and perform complex operations based on the values stored in those variables.
To send an email with an attachment in SSIS, you can use the Script Task along with .NET libraries like `System.Net.Mail`. Here's a step-by-step guide on how to accomplish this:
1. Add a Script Task:
- Drag and drop a Script Task from the SSIS Toolbox onto the Control Flow design surface.
2. Edit the Script Task:
- Double-click the Script Task to open the Script Task Editor.
- Click on "Edit Script" to open the Visual Studio for Applications (VSA) environment.
3. Write Code to Send Email with Attachment:
- Write C# or VB.NET code within the Script Task to send the email with an attachment. Below is an example in C#:
-------------------------------------C#----------------------------------------
using System.Net.Mail;
using System.Net.Mime;
public void Main()
{
// Email configuration
string smtpServer = "your_smtp_server";
int smtpPort = 587; // or any other port
string fromEmail = "your_email@example.com";
string toEmail = "recipient@example.com";
string subject = "Subject of the Email";
string body = "Body of the Email";
// Create a MailMessage object
MailMessage mail = new MailMessage(fromEmail, toEmail, subject, body);
mail.IsBodyHtml = true;
// Add attachment
Attachment attachment = new Attachment("C:\\Path\\To\\Your\\File.txt", MediaTypeNames.Text.Plain);
mail.Attachments.Add(attachment);
// Create a SmtpClient object
SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort);
smtpClient.EnableSsl = true;
// Add credentials if required
smtpClient.Credentials = new System.Net.NetworkCredential("your_username", "your_password");
try
{
// Send the email
smtpClient.Send(mail);
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
// Handle any errors
Dts.Events.FireError(0, "Send Email Script", ex.Message, String.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
------------------------------------------------------------------------------------
4. Testing and Execution:
- Test the Script Task by running the SSIS package. Ensure that the email with the attachment is sent successfully to the specified recipient.
- Monitor the SSIS package execution to verify that the Script Task runs without errors.
5. Error Handling and Logging:
- Implement error handling within the script to capture and handle any errors that may occur during the email sending process.
- Consider logging details of successful email sends and any errors encountered for auditing and troubleshooting purposes.
6. Deployment and Scheduling:
- Once tested successfully, deploy the SSIS package to the production environment.
- Schedule the package to run at the desired intervals using SQL Server Agent jobs or another scheduling mechanism.
Replace placeholders such as `your_smtp_server`, `your_email@example.com`, `recipient@example.com`, `C:\\Path\\To\\Your\\File.txt`, `your_username`, and `your_password` with your actual email server details, file path, and credentials.
Using a Script Task allows for flexibility and customization in sending emails with attachments in SSIS.
To achieve this task in SSIS, you can follow these steps:
Add Data Flow Task:
Drag and drop a Data Flow Task onto the Control Flow design surface.
Within the Data Flow Task: a. Add a Source component to query data from the database. You can use an OLE DB Source or an ADO.NET Source, depending on your preference and the type of database you're querying. b. Configure the Source component with your database connection and the SQL query to retrieve the desired data. c. Add any necessary transformations or data manipulation components if needed. d. Add a Flat File Destination component to export the queried data to a flat file. Configure the Flat File Destination with the desired file path, delimiter, and other settings.
The Row Count Transformation in SQL Server Integration Services (SSIS) is used to count the number of rows passing through a data flow path. It's commonly used for monitoring and auditing purposes or for implementing conditional logic based on the number of rows processed. Here's how you can use the Row Count Transformation in SSIS:
Add Row Count Transformation:
Start by adding a Data Flow Task to your Control Flow.
Within the Data Flow Task, add the data source (e.g., OLE DB Source) and any necessary transformations.
Drag the Row Count Transformation from the SSIS Toolbox onto the Data Flow design surface and connect it to the data flow path.
Configure Row Count Transformation:
Double-click the Row Count Transformation to open its editor.
In the editor, you can specify whether to count rows based on the entire data flow or only a subset of the rows.
You can also choose to count rows in memory or count rows in the data flow buffer.
Optionally, you can assign the row count to a variable by selecting the appropriate option and specifying the variable name.
Usage:
After configuring the Row Count Transformation, you can use the row count for various purposes within your SSIS package:
Conditional Split: You can route data based on the row count. For example, if the row count exceeds a certain threshold, you may want to take a different path in your data flow.
Send Mail Task: You can use the row count to determine whether to send an email notification. For example, you may want to send an email if no rows are processed or if a certain number of rows are processed.
Logging: You can log the row count to a database table or a flat file for auditing purposes.
You can effectively use the Row Count Transformation in SSIS to count rows passing through a data flow path and implement conditional logic or monitoring based on the row count.
The Row Count Transformation in SQL Server Integration Services (SSIS) is used to count the number of rows passing through a data flow path. It's commonly used for monitoring and auditing purposes or for implementing conditional logic based on the number of rows processed. Here's how you can use the Row Count Transformation in SSIS:
Add Row Count Transformation:
Start by adding a Data Flow Task to your Control Flow.
Within the Data Flow Task, add the data source (e.g., OLE DB Source) and any necessary transformations.
Drag the Row Count Transformation from the SSIS Toolbox onto the Data Flow design surface and connect it to the data flow path.
Configure Row Count Transformation:
Double-click the Row Count Transformation to open its editor.
In the editor, you can specify whether to count rows based on the entire data flow or only a subset of the rows.
You can also choose to count rows in memory or count rows in the data flow buffer.
Optionally, you can assign the row count to a variable by selecting the appropriate option and specifying the variable name.
Usage:
After configuring the Row Count Transformation, you can use the row count for various purposes within your SSIS package:
Conditional Split: You can route data based on the row count. For example, if the row count exceeds a certain threshold, you may want to take a different path in your data flow.
Send Mail Task: You can use the row count to determine whether to send an email notification. For example, you may want to send an email if no rows are processed or if a certain number of rows are processed.
Logging: You can log the row count to a database table or a flat file for auditing purposes.
You can effectively use the Row Count Transformation in SSIS to count rows passing through a data flow path and implement conditional logic or monitoring based on the row count.
Email Body
Query data from the database
Use Recordset destination to save data in memory
Use Foreach Loop to write rows to email body
Foreach Loop Container
In SQL Server Integration Services (SSIS), the Foreach Loop Container is a control flow element used for looping through a collection of items such as files, folders, or database objects. It's particularly useful when you need to perform repetitive tasks on multiple items within a specified directory or collection.
Here's a general overview of how the Foreach Loop Container works:
1. Enumerator: You specify an enumerator type, which determines the collection of items to iterate over. Common enumerators include Foreach File Enumerator (for files in a directory), Foreach ADO Enumerator (for rows in a database table), and Foreach Item Enumerator (for a collection of specified items).
2. Collection: You define the collection that the enumerator should iterate over. For example, if you're using the Foreach File Enumerator, you specify the folder path and optionally a file mask to filter the files.
3. Variable Mapping: Within the Foreach Loop Container, you typically use variables to store information about each item as you iterate through the collection. You map these variables to the properties of the current item during each iteration.
4. Loop Body: Inside the container, you place the tasks or components that you want to execute for each item in the collection. These tasks will run once for each item in the collection.
5. Iteration: During each iteration of the loop, the Foreach Loop Container updates the variables with information about the current item, then executes the tasks within the loop body.
6. Completion: Once all items in the collection have been processed, the loop ends, and the control flow continues with the tasks or components following the Foreach Loop Container.
Here's a simple example scenario: Suppose you have a directory containing multiple CSV files, and you want to import each file into a SQL Server database. You could use a Foreach Loop Container to iterate over each file in the directory, with tasks inside the loop to import the data from each file into the database.
The Foreach Loop Container provides flexibility and automation for handling repetitive tasks within SSIS.
It allows you to dynamically process multiple items without the need to hard-code each item individually. This makes it a powerful tool for automating ETL (Extract, Transform, Load) processes and other data integration tasks within SSIS.
Recordset Destination
In SSIS, the Recordset Destination is a data flow destination component that allows you to store the result set of a query or the output of a data flow task into an object variable as an ADO.NET dataset or recordset. This object variable can then be used elsewhere in the SSIS package for further processing.
Here's how it generally works:
1. Configuring the Recordset Destination: You drag and drop the Recordset Destination onto the Data Flow canvas in SSIS. Then, you configure it by specifying the destination connection manager (typically an ADO.NET connection manager) and the object variable where you want to store the result set.
2. Mapping Columns: If you're storing the output of a data flow task, you map the columns from the data flow output to columns in the recordset destination. If you're storing the result set of a query, you typically won't need to map columns as they're already defined by the query.
3. Execution: When the data flow task containing the Recordset Destination executes, it retrieves the data from the source (such as a database table or another data flow task) and stores it in memory as a dataset or recordset object.
4. Usage of Object Variable: Once the data is stored in the object variable, you can use it in subsequent tasks or components within the SSIS package. For example, you might use it as a data source in another data flow task, or you might iterate through the rows using a Foreach Loop Container.
The Recordset Destination is particularly useful in scenarios where you need to manipulate or process the data within the SSIS package itself, rather than immediately loading it into a destination database. It provides flexibility in handling intermediate data within the package's workflow.
For example, you might use the Recordset Destination to store the result set of a complex query, perform additional data transformations or calculations on that data within the package, and then finally load the transformed data into a destination database.
Overall, the Recordset Destination is a valuable tool for managing and manipulating data within SSIS packages, enabling you to perform more advanced ETL processes and data integration tasks.
In SQL Server Integration Services (SSIS), formatting the email body is typically done using a Script Task or an Expression within an SMTP Connection Manager. Here's a basic outline of how you can achieve this:
1. Using a Script Task:
- Add a Script Task to your SSIS package's Control Flow.
- Open the Script Task editor and choose the appropriate language (C# or VB.NET).
- Write code within the Script Task to construct the email body according to your desired format. You can use HTML formatting for styling.
- Assign the constructed email body to a variable.
- Pass this variable to an SMTP Connection Manager or another component responsible for sending the email.
2. Using Expressions in SMTP Connection Manager:
- If you're using an SMTP Connection Manager to send emails, you can use expressions to dynamically construct the email body.
- Create a variable that holds your email body content, formatted as desired (e.g., using HTML).
- Set the Expressions property of the SMTP Connection Manager to dynamically assign the email body variable to the appropriate property (such as MessageSource or MessageBody).
Here's a simplified example of how you might construct an email body with HTML formatting using a Script Task in C#:
------------------------------- C# --------------------------------------------------
string emailBody = "<html><body>";
emailBody += "<h2>This is a formatted email body</h2>";
emailBody += "<p>This is a paragraph of text.</p>";
emailBody += "</body></html>";
// Assign the email body to a variable to pass to the SMTP Connection Manager
Dts.Variables["User::EmailBody"].Value = emailBody;
---------------------------------------------------------------------------------------
Remember to properly configure your SMTP Connection Manager to use HTML formatting for the email body if you're sending HTML-formatted content.
Using these methods, you can format the email body in SSIS to meet your specific requirements, whether it involves simple text or more complex HTML formatting.
In a real-world SSIS project for patient post-visit follow-up emails, the goal is to automate the process of sending personalized emails to patients after their visits to a healthcare facility. Here's a step-by-step guide on how you might approach this project:
1. Requirements Gathering:
- Meet with stakeholders, including healthcare providers and administrators, to understand the objectives of the post-visit follow-up emails. Determine the content, timing, and frequency of the emails.
- Identify the data sources required for the project, such as the patient database, appointment records, and email templates.
2. Data Source Configuration:
- Set up connection managers in SSIS to connect to the patient database and any other relevant data sources.
- Configure connection properties to access patient demographics, appointment details, and other necessary information.
3. Data Flow Design:
- Design the data flow tasks to extract patient information, appointment details, and other relevant data from the source systems.
- Use SSIS components such as SQL Server Source, Excel Source, or Flat File Source to retrieve patient data.
- Implement transformations to filter, join, or aggregate data as needed to create a dataset for generating personalized emails.
4. Email Template Creation:
- Develop email templates that will be used for the post-visit follow-up emails. These templates should be personalized with patient-specific information such as name, appointment date, and any follow-up instructions.
- Consider using placeholders or variables within the email templates to dynamically insert patient data retrieved from the SSIS package.
5. Email Generation:
- Use SSIS Script Task or Expression Task to dynamically generate personalized emails based on the email templates and patient data.
- Write code to construct the email body, replacing placeholders with actual patient information retrieved from the dataset.
6. SMTP Configuration:
- Configure an SMTP Connection Manager in SSIS to connect to the email server used for sending emails.
- Specify the SMTP server address, port number, authentication method, and sender email address.
7. Email Sending:
- Implement SSIS components such as the Send Mail Task or Script Task to send the personalized emails using the configured SMTP connection.
- Set up the email subject, recipient email addresses (patients), and email body (constructed in the previous step) dynamically within the SSIS package.
8. Error Handling and Logging:
- Implement error handling mechanisms to capture and handle any errors that occur during the email sending process.
- Log details of successful email sends, as well as any errors encountered, for auditing and troubleshooting purposes.
9. Testing and Deployment:
- Test the SSIS package thoroughly in a development or testing environment to ensure that emails are generated and sent correctly.
- Deploy the SSIS package to the production environment and schedule it to run at appropriate intervals (e.g., daily or weekly) using SQL Server Agent jobs or another scheduling mechanism.
10. Monitoring and Maintenance:
- Monitor the SSIS package executions and email sending process to ensure that emails are being delivered as expected.
- Perform routine maintenance tasks such as updating email templates, adjusting scheduling settings, and handling any changes to data sources or email server configurations.
By following these steps, you can automate the process of sending personalized post-visit follow-up emails to patients using SSIS, streamlining communication and improving patient satisfaction in a healthcare setting.
A complete notification solution encompasses various components and functionalities to effectively deliver messages, alerts, updates, and reminders to customers across different platforms and devices.
This course is designed for beginners or experts who would like to learn step by step on how to create a notification system. In any industry, continuous communication to the customers is a key. It is important to keep your customer informed to ensure better customer satisfaction.
Business Use Case
School Management System – Send new students to the admission officer.
Doctors Office – Send new patients/ referral list.
Insurance Company - Send invoices/ quotation to new members.
Job Application - Send instant messages/email as the application changes status such as New Applicants, Short-listed, Called for Interview etc.
After completing this course, you will be able to:
Create a complete notification system
Support for delivering notifications through multiple channels such as text messages or emails
Communicate to customer in their native/preferred language to foster trust and credibility
Support for rich media content such as images, videos, GIFs and interactive elements
Work for any industry or for yourself as a side hustle.
Real-World Project
You will have the opportunity to create a Patient Post-Visit Follow-up tool for a KGM Medical Center.
Patient post-visit follow-up tool generates the customized email content based on the preferred language, processes and sends the email to patients.