Although each of the component types performs very different functions, the way you build each custom component type is very similar. To set up each of the component types, start with the following general steps:
Creating the SolutionIn this step, you'll create a new solution for the component to live in. This step is identical for all component types, but for this discussion you'll be building a task.
Adding a Strong Name and Key File.NET requires that the component have a strong name. To do this, you must create a key file and link the key file to the component. This step is identical for all component types. Fortunately, Visual Studio makes this very easy, as follows:
Referencing SSIS and Other AssembliesAll component types need this step, but depending on the type of component, the assemblies you reference will be different. For Foreach Enumerators, connection managers, log providers, and tasks, you need to reference the Microsoft.SqlServer.Dts.Runtime assembly. Caution In rare circumstances, you might need to reference the Microsoft.SqlServer.Dts.Runtime.Wrapper assembly as well. However, doing so can cause some confusion as there are many similarly named objects in both assemblies. As a rule, when building runtime components, you should not need to reference the wrapper assembly and should avoid doing so unless absolutely required. For data flow components, you need to use the following namespaces and reference the associated assemblies:
To reference each of the assemblies in your project, follow these steps:
Defining the ClassThere are two parts to this step. One is to derive from the base component so that you get the default behavior of the base class. The other is adding attributes. The attributes provide information that the runtime examines when enumerating the components. This step is different for each component type. Deriving from the Base ClassIntegration Services provides an abstract base class for each of the component types. Following is a list of the base class names:
By deriving from one of these base classes, you can create the corresponding SSIS class. For this sample, derive the SampleTask from the Task base. When you have done so, the SampleTask.cs file should contain the following code: using System; using System.Collections.Generic; using System.Text; using Microsoft.SqlServer.Dts.Runtime; namespace SampleTask { public class SampleTask : Task { } } Adding AttributesThe second part of this step is to identify the new class to Integration Services. Integration Services enumerates components based on two criteria: location and attributes. LocationIntegration Services components are installed in the DTS subfolder of the SQL Server installation location. The default location is in the Program Files directory. C:\Program Files\Microsoft SQL Server\90\DTS Under this folder, there are five folders of interest to this discussion, as follows:
This is where Integration Services looks when enumerating components and does not detect managed components in any other location. In the Compile and Install step described later, you'll see how to set up the project to directly compile the component into the correct folder. AttributesIntegration Services opens each of the assemblies in those folders and reflects on the attributes of the contained classes. This is how the TaskInfos, PipelineComponentInfos, and other info objects on the Application object are enumerated. Table 23.1 shows the attributes and their purpose.
For the sample task, in the line above the class declaration, add the following attribute and parameters: [ DtsTask( DisplayName="SampleTask", Description="A sample task", TaskContact="SampleTask, Copyright © Your Name") ] With the attribute added, everything necessary for the designer to identify and load the component is in place. The next step is to compile and install the component. Compiling and InstallingTo make a component visible to Integration Services, you need to compile it, place it in the GAC, and move the component assembly to one of the enumeration folders under the DTS folder mentioned previously. For the sample task, that is the DTS\Tasks folder. Setting the Output PathTo automatically move the component to the correct folder when you build it, set the output path on the Project Properties Build page. Note It's important to remember that, when correctly installed, there is a copy of the component in two locations. The following location, on the file system under the SQL Server folder, is for enumeration only. In fact, if you never do any design work on a machine, but only run packages, there is no need for the components in the special folders. When loading packages, SSIS only references the copies of the components in the GAC. The following steps show how to set up the output path for the compiled component:
Figure 24.4 shows the correct settings in the Project Properties dialog box. Figure 24.4. Setting the output folder for the sample taskInstalling into the GACThe next step is to install the component into the GAC:
Caution Make sure that the gacutil.exe utility is on the path so that this command will succeed. Building the ComponentNow you need to build the component. If you've got everything right in the sample, the assembly compiles directly to the folder location where it can be enumerated by the designer and another copy gets placed into the GAC. Then, you can open the Business Intelligence Development Studio (BIDS) and add the task in the Toolbox.
The message box is telling you that there is no TaskUI for the task. That's because you haven't built a TaskUI for the sample task yet. However, if you run the package, the task will still successfully execute because the base class provides the default Execute methods. Also, even though there is no task UI, you can still modify properties through the property grid. How the Runtime Finds Your Installed TasksTo understand how the runtime finds your custom task and other components, take a look at the Registry by opening regedit.
A number of subkeys are in the Setup key. Click on the DTSPath key and look at the Default value. For most installs, this is C:\Program Files\Microsoft SQL Server\90\DTS\ and is the fully qualified path to the base directory where tasks are stored. If this key isn't there, the application object searches: HKLM\Software\Microsoft\MSSQLServer\Setup for the fully qualified base directory. If neither of these values is found, the enumeration fails. After retrieving the base directory, the runtime appends "\tasks" to the base path to create the final directory where tasks assemblies are stored to generate the folder path. The runtime reflects on all assemblies in this folder and tries to find classes with the DtsTask attribute. If you look in that folder, you'll notice that the stock task assemblies are also stored there. Again, Microsoft has no special location or process for including stock components. The same rules apply to stock and custom components, so all components are enumerated and included in the designer in the same way. This sample task is an example of the most rudimentary component you can write. It shows how simple it is to start, code, install, add to the designer, and execute with very little effort. However, it is only a simple component with no real purpose other than to serve as a sample. The following discussion describes how to expand on the basic sample and make it a full-featured SSIS citizen. |