DTS Example: Adding Properties and Icons in Visual Basic

DTS Programming

DTS Programming

DTS Example: Adding Properties and Icons in Visual Basic

You can modify a Data Transformation Services (DTS) custom task so that users can:

  • Enter and change the task description and update the icon label with that description.

  • Enter and change the text of the displayed message.

  • Add one or more icons to the task component.
Writing Task Description and Message Properties

To enter and save the task description, implement the Description property of the CustomTask interface so that it saves the value to which it is set and returns that value when the property is read. Also, you must add a Description property outside of the CustomTask interface and tie the properties together so that setting the value of either causes both to be changed. For more information, see DTS Custom Task Fundamentals.

To enter and save the message text, add a property (called Message in the sample code below) and use that property value in the MsgBox function. Save the value to which Message is set and return that value when the property is read.

Example

This is the Microsoft® Visual Basic® code for adding these properties to the basic custom task:

Implements DTS.CustomTask

Private mstrTaskName    As String
Private mstrDescription As String
Private mstrMessage     As String

Private Sub CustomTask_Execute(ByVal pPackage As Object, ByVal pPackageEvents As Object, _
            ByVal pPackageLog As Object, pTaskResult As DTS.DTSTaskExecResult)
    MsgBox mstrMessage, vbExclamation, mstrDescription
End Sub

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

Private Property Get CustomTask_Description() As String
'Implements Task.Description.
    CustomTask_Description = mstrDescription
End Property

Private Property Let CustomTask_Description(ByVal strNewDescr As String)
'Implements Task.Description.
    mstrDescription = strNewDescr
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

Public Property Get Message() As String
'Implements CustTask.Message.
    Message = mstrMessage
End Property

Public Property Let Message(ByVal strNewMsg As String)
'Implements CustTask.Message.
    mstrMessage = strNewMsg
End Property

Public Property Get Description() As String
'Implements CustTask.Description.
    Description = mstrDescription
End Property

Public Property Let Description(ByVal strNewDescr As String)
'Implements CustTask.Description.
    mstrDescription = strNewDescr
End Property
Adding Icons to a Custom Task Component

In a Visual Basic project, you typically assign an icon to the Icon property of each form in the project. Then you select one of the forms to supply the icon for the component. However, DTS Designer is not able to access an icon specified in this way.

For DTS custom tasks, you must add a resource file to the Visual Basic project and add one or more icons to the resource file. When you register a custom task, all the icons in the resource file will appear under Select Icon in the Register Custom Task dialog box in DTS Designer. 

To add icons to the DTS custom task

  1. On the Task menu, click Unregister Custom Task, and then select the task you registered.

  2. In the Visual Basic development environment, replace the Visual Basic code in the CustTask class with the upgraded code from the example.

  3. Add a resource file to the project and add one or more icons to the resource file.

  4. On the File menu, click Make DTSMinimum.dll to build the component.

    You may need to close SQL Server Enterprise Manager first to avoid a "permission denied" error.

  5. Register the custom task in DTS Designer. The icons you added to the project resource file should appear in the Register Custom Task dialog box.

    For more information, see Registering a DTS Custom Task.

  6. Drag a copy of the custom task onto the design sheet. Set values for Description and Message, and then close the properties grid. The icon label should change to the value of Description.

  7. Execute the package.

    In the message box, the value of Message is displayed.

If you select Binary Compatibility from the Component tab of the Project/Properties dialog box in Visual Basic, you do not have to complete Steps 1 and 5 of this procedure. However, selecting Binary Compatibility severely restricts the changes you can make to the public interface of the custom task.

Registration Problems in DTS Designer

If you rebuild a custom task component before unregistering it in DTS Designer, subsequent attempts to unregister the component will fail. DTS Designer will be unable to find the component file.

To recover from registration problems in DTS Designer

  1. From a DOS window, set the default device and directory to the folder containing the custom task component DLL. Unregister the component with this command:
    regsvr32 /u component.dll
    
  2. Close DTS Designer, right-click Data Transformation Services, and then click Properties. Do one of the following:
    • If the Turn on Cache check box is selected, click Refresh Cache.

    • If the Turn on Cache check box is not selected, the Refresh Cache button will be unavailable and you can skip this step.
  3. Rebuild the custom task component DLL.

  4. Reopen SQL Server Enterprise Manager and DTS Designer. The custom task should not appear on the Task menu or Task toolbar.

  5. On the Task menu, click Register Custom Task and provide the information necessary to register the custom task in DTS Designer.

    Caution  Do not attempt to unregister components by deleting the registered file and removing the registry entries with a registry cleaning utility. Many utilities only partially remove the registry entries. You will then not be able to use regsvr32.exe because it calls the DLLUnregisterServer entry point in the registered component, which you have deleted.

See Also

CustomTask Object

Execute Method

Properties Collection