Technical Article

ActiveX - Clean Up Unused Connections

,

This ActiveX Script runs in DTS Designer and will clean up all unused connection objects.

This allows you to rename connections at will by selecting "New Connection" and typing a new name.

It also allows you to copy and paste connections then rename them.

Then you can cleanup leftover connections when development is complete.

'**********************************************************************
'* Fun With ActiveX Scripts
'**********************************************************************
'* Clean Up Unused Connections
'**********************************************************************
'* Author: 
'* Lane Tharp 
'* CountryWide Financial Services
'* Performance Management Group
'* Plano, Texas
'* 2004/12/31
'* ----------------------------------------
'* Description:
'* This Script loops through every connection in a package and removes it if unused.
'* ----------------------------------------
'* Useage:
'* 1. Add an ActiveX Script Task to Package being renamed in DTS Designer. 
'* 2. Disable this Task in workflow properties so it does not run with package. 
'* 3. Copy this script into the ActiveX Task. 
'* 5. Make a backup copy of the package. (Do not skip this step) 
'* 6. Save the package. (Do not skip this step) 
'* 7. Execute the ActiveX script in DTS Designer, save, and close the package.
'*-------------------------------------------------------------------------------------
'* Debug Note:
'* - This script is not intended for unnattended execution.
'* - Do not edit scripts in the ActiveX Task Properties in DTS. (You will go blind.)
'* - Edit as .vbs file in, and *debug* scripts in the Microsoft Script Editor. 
'-------------------------------------------------------------------------------------
Function Main()
    On Error Resume Next    
    Stop
    Dim loPackage
    Dim loConnections
    Dim loConnection
    Dim loTasks
    Dim loTask
    Dim loProperties
    Dim loProperty
    Dim lbConnectionUsed
    Set loPackage = DTSGlobalVariables.Parent
    Set loConnections = loPackage.Connections
    Set loTasks = loPackage.Tasks
    ' Restart After Collection Change
    Do
        ' Loop Through Connections
        For Each loConnection In loConnections
            lbConnectionUsed = False
            ' Loop Through Tasks
            For Each loTask in loTasks
                Set loProperties = loTask.Properties
                ' Loop Through Properties
                For Each loProperty in loProperties
                    If Instr(loProperty.Name, "ConnectionID") Then
                        If loProperty = loConnection.ID Then
                            lbConnectionUsed = True
                            Exit For
                        End If
                    End If
                Next
                If lbConnectionUsed = True Then
                    Exit For
                End If
            Next
            If lbConnectionUsed = False Then
                loConnections.Remove loConnection.Name
                Exit For
            End if
        Next
        If lbConnectionUsed = True Then 
            Exit Do
        End If
    Loop
    Set loPackage = Nothing
    Set loConnections = Nothing
    Set loConnection = Nothing
    Set loTasks = Nothing
    Set loTask = Nothing
    Main = DTSTaskExecResult_Success
End Function

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating