DTS Example: Basic Custom Task in Visual Basic

DTS Programming

DTS Programming

DTS Example: Basic Custom Task in Visual Basic

The following code example implements a basic Data Transformation Services (DTS) custom task in Microsoft® Visual Basic®.

When executed, the application displays a fixed message in a message box. The Execute method displays the message box. The Name property returns the value to which it was set. The Description property and Properties collection are placeholders.

Implementing a Basic DTS Custom Task

Use the following Visual Basic code to implement a basic DTS custom task:

Implements DTS.CustomTask

Private mstrTaskName    As String

Private Sub CustomTask_Execute(ByVal pPackage As Object, ByVal pPackageEvents As Object, _
            ByVal pPackageLog As Object, pTaskResult As DTS.DTSTaskExecResult)
    MsgBox "Minimum custom task!", vbExclamation
    pTaskResult = DTSTaskExecResult_Success
End Sub

Private Property Get CustomTask_Properties() As DTS.Properties
'CustomTask_Properties returns Nothing.
End Property

Private Property Get CustomTask_Description() As String
'Description returns empty string.
End Property

Private Property Let CustomTask_Description(ByVal RHS As String)
'Description set value is discarded.
End Property

Private Property Get CustomTask_Name() As String
'Implements Task.Name.
    CustomTask_Name = mstrTaskName
End Property

Private Property Let CustomTask_Name(ByVal strNewName As String)
'Implements Task.Name.
    mstrTaskName = strNewName
End Property

To build this DTS custom task in Visual Basic

  1. In the Visual Basic development environment, create a new Microsoft® ActiveX® DLL project.

  2. On the Project menu, click References, and under Available References, select the check box for Microsoft DTSPackage Object Library. Then, on the Project menu, click Properties, and in the Project name box, change the project name from Project1 to something meaningful, such as DTSBasic.

  3. Change the name of the class module from Class1 to something meaningful, such as CustTask.

  4. Copy the Visual Basic code from the example and paste it into the class module you have just renamed.

  5. Build the component by selecting File/Make DTSBasic.dll.

This procedure builds DTSBasic.dll and registers it in the operating system registry. The component is registered as a generic DLL. The registration does not specify the component category for DTS tasks. The custom task can be used in DTS applications but must be registered in DTS Designer before being used there. For more information about the DTS task component category, see Registering a DTS Custom Task.

To register the task in DTS Designer

  1. Open SQL Server Enterprise Manager, right-click Data Transformation Services, and then click New Package.

  2. On the Task menu, click Register Custom Task.

  3. In the Task description box, enter an appropriate task description, and then in the Task Location box, enter the path to DTSMinimum.dll. Click the browse (...) button to search for DTSMinimum.dll.

    On the Task menu, the custom task and icon appear. The default DTS task icon is displayed because there are no icons in DTSBasic.dll.

To run the registered task

  1. From the Task toolbar, drag the custom task icon to the design sheet.

    The default property grid appears, but no properties are displayed.

  2. Click OK.

    The task icon description disappears. You must click Execute to display the task icon description.

See Also

CustomTask Object

Execute Method

Properties Collection