October 31, 2012 by Kenneth Fisher
This is just a quickie post to answer a question on how to loop through multiple servers in SSIS. There are a lot of options I’m not going to go into here due to lack of time. If someone expresses interest I’ll try to do a more detailed post later.
- First create an OLE DB connection manager pointing to some random server.
- Next create a FOR EACH LOOP container.
For simplicities sake I’m going to show this loop using a Foreach Item Enumerator. Personally, I like to use a table and a Foreach from Variable Enumerator but it takes longer to explain.
- Under the Collection “tab” change the Enumerator to “Foreach Item Enumerator”.
- Add a single column.
- In that column list out the servers you want to loop through.
- Under the Variable Mappings “tab” add a new variable called “ServerName” with a value type of “String”. Make sure the Index is set to 0.
- Next go to the properties of the connection manager. Look for one called Expressions. Select it and click on the ellipsis (…).
- Under properties select ServerName.
- Then Click on the ellipsis (…) under Expression.
- Select the variable User::ServerName and drag it into the Expression box.
At this point when you run your Foreach Loop Container each loop it makes will cause the Connection Manager ConnMan1 to point to a different server.
I realize this was rather fast, and I would have loved to have shown some sample output. Unfortunately as I stated at the beginning I’m rather pressed for time today and want to get this out quickly to answer a post.
Here are links to the other two posts in this series. Step three has the actual DTSX for download. You will have to rename it to get it to work as it has a DOCX extension on the end of it. I couldn’t figure out how to get a DTSX extension to load.