This is my much overdue follow-up blog from the presentation I gave to the New York SQL Server User Group. In this post, I am going to provide some additional resources to supplement the presentation, check out the following blog post on different performance tuning techniques that can be used for SSIS.
With the Retain Same Connection property I was recently able to more than double the performance of my SSIS package for a client. The package was looping over hundreds of thousands of files and logging the file names into a table to be later processed.
Retain Same Connection is a property setting found on connection managers. By default this property is set to false which means that each time the connection manager is used the connection is opened and subsequently closed. However in a situation like mine this can significantly degrade overall performance as the package has to open and close that connection hundreds of thousands of times. In this blog I’m going to set up a very basic example and walk through setting up this connection manager.
Here I have set up two connection managers. Both connection managers point to the same database. It’s important to note that if you are using Project Level Connection managers in SQL 2012 that setting this property inside any one package will persist across all packages. Therefore I create two connection managers.
Inside the package I am simply using a for each loop task to loop through a list of files in a directory and then I load the file names into a table using an Execute SQL task. For demo purposes I have two examples in one package.
- The FELC on the left takes 30 Seconds to run.
- The FELC on the right takes 11 Seconds to run.
Let’s now discuss how and where we can set this property.
Right click on your connection manager found in the connection managers pain inside the package and select Properties.
Inside the properties window find the property “RetainSameConnection” and set the value to “True”. Now the connection will remain open for the duration of the package.
As always thanks for looking!
Today we are going to address a very common FTP question: “How can I get a list of the files that are on my FTP Server?”
This is a task that can be accomplished very easily with the Task Factory Secure FTP component and this walk through will provide step by step directions. If you are interested in Task Factory and the more than 40 tasks you can find the free trial here:
Here we will use the “Get list of files” option and store all the files for a given directory into an object variable. We will use a Foreach loop container to iterate through the object variable and then an Execute SQL task to write each file name to a table in our database. This walkthrough is broken down into three sections.
- Part 1 – Setting up the Secure FTP component to get List of Files
- Part 2 – Setting up the For Each Loop to read the the object variable
- Part 3 – (Optional) Setting up the Execute SQL Task to write the file names to a table.
Part 1 – Configuring the Secure FTP site to Get List of Files from server.
- Start a new package and drag the Secure FTP task into your control flow from the toolbox.
- Next right click on the Secure FTP Task and click edit.
- Steps 4-7 below are in screenshot 1
- What will this task do? Select “Get list of files” from the drop down menu.
- For SFTP Connection Manager either choose an existing connection manager or create a new one if don’t have one set up.
- For your Directory location on server you have two options:
- First you can choose to click the ellipsis button and hard code the directory location.
- Second you can choose to store the directory location in a variable
- Next create an object variable to store the list of file names in from the server. (objFilesList)
Part 2 – Configuring the For Each Loop to iterate through the object variable
- Pull a Foreach Loop container into the Control Flow and drag the precedence constraint from the Secure FTP task to the Foreach loop container.
- Steps 3-6 can be found in Screenshot 2
- Open the For Each container and click on the Collection tab.
- For “Enumerator” choose “Foreach From Variable Enumerator” from the drop down.
- Next select the object variable you specified in the Secure FTP component. (objFilesList)
- Finally click the Variable Mappings tab.
- On the Variable Mappings tab select a string variable to store the file name in. (strFileName)
- Make sure Index is set to 0. (Screenshot 3)
- Click Ok.
Optional: (This section simply shows how to map variables in an Execute SQL Task and helps with visualization of each iteration of the Foreach Loop through the list of files on our FTP.)
Part 3 – Setting up the Execute SQL Task to read the string variable
(This section has been added for completeness and is fully optional.)
Note: For this example I have created a simple table with four columns:
CREATE TABLE [dbo].[FilesOnSftp](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Directory] [varchar](50) NULL,
[FileName] [varchar](50) NULL,
[DateLoaded] [date] NULL)
- Pull an Execute SQL Task from the toolbox into the Foreach Loop container.
- Create a new variable called strSftpDirectory and give it a value of /
- Right click on the Execute SQL Task and click Edit to bring up the Editor
- For “Connection” choose the connection manager to your database.
- Click and highlight “SQLStatement” and then click the Ellipsis button that appears on the right.
- Clicking the Ellipsis button will give you a pop up window, this is where we enter our Insert SQL Statement. Here is the syntax I used if you are following along with the tutorial:
INSERT INTO dbo.FilesOnSftp
([Directory], [FileName], [DateLoaded])
- Now its time to map the parameters. Click on the Parameter Mapping tab. (Screenshot 5)
- Click the Add button and then select “strSftpDirectory” for Variable Name.
- For data type choose Varchar and change the Parameter Name to 0.
- Click the Add button a second time and select strFileName for the Variable Name.
- For data type choose Varchar and change the Parameter Name to 1. Click ok to save changes.