Creating the first SSIS Package
After understanding the SSDT environment, you will be able to make your first SSIS Package. Depending on the Data Integration project's complexity, it's always recommended to think carefully while selecting tasks and components to apply, as well as the order in which to execute them.
In this recipe, the first package created will read the number of records in an Adventure Works Microsoft Sample table and store it inside the SSIS Package.
Getting ready
You can reuse the recipe created in the previous section (adding a new package to it), or start from scratch as explained in the following steps:
Open SQL Server Data Tools (SSDT).
Click on New Project… and a Windows dialog will appear.
Click on the Business Intelligence Projects tab and under the Installed Templates section, select Integration Services Project.
Provide a name and location for the SSIS project and an empty structure as well as a package will be created.
In the Solution Explorer, select the empty package.dtsx and rename it to:
P01_FirstSSISPackage.dtsx
.
How to do it...
Now that the SSIS project is created, ensure that the empty package created by default is open and follow these steps:
Create an OLEDB Connection to the Adventure Works Microsoft sample database at the package level. (As already mentioned, if you create this connection in the Solution Explorer window, the connection will be created at the project level and will be automatically included inside all the existent packages).
In the Configure OLE DB Connection Manager Editor, select New... to create a new connection. If the connection already exists in the Data Connections list then select it here.
Tip
Ensure that the Control Flow tab is selected in the Package Designer area.
Drag-and-drop Execute SQL Task from SSIS Toolbox and place into the control flow design surface.
Double-click to edit Execute SQL Task or right-click and click on the Edit option.
Set the Connection property of the task to the connection created in step two.
Set the Result set to Single row.
Add the SQL Statement:
SELECT COUNT(*) AS NR_ROWS FROM SalesLT.Customer
to get the number of records from theCustomer
table.Drag-and-drop Script Task from SSIS Toolbox and place into the Package Designer area and edit it by double-clicking on it.
Create a new variable to store the value provided by the previous task and add a message box inside the script (the script task is explained more clearly in Chapter 11, Event Handling and Logging) as follows:
MsgBox (Dts.Variables(0).Value, MsgBoxStyle.Information)
Run the package by pressing F5.
How it works...
This recipe created a basic SSIS Package that included the most used tasks among SSIS projects: the Execute SQL Task, to communicate with a database through SQL queries and the Script Task that allows us to create some custom "work" when other tasks fall short. Naturally, it is too early to go into details with these two tasks, but this way it's possible to have an initial look at these common tasks.