Creating a Custom Increment Task Sample
Updated: 5 December 2005
The Increment Task sample demonstrates how to programmatically create custom tasks and their associated user interfaces. This sample is not supported on Itanium-based operating systems. The code sample implements the following functionality:
- Overriding of the Microsoft.SqlServer.Dts.Runtime.Task base class.
- Persistence support.
- Breakpoint support.
- Custom events. This particular code sample enters a loop during execution. A private integer variable is incremented on each iteration of the loop. The properties InitialValue, IncrementValue, and LoopCount control processing in the loop. These properties are set by using the custom user interface that is implemented by the task. The custom breakpoints OnBeforeIncrement and OnAfterIncrement and their events are raised before and after the variable is incremented. The ExecutionResult property contains the value of the internal incremented variable after the task has finished running.
| Important: |
| Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. |
Running the Sample
If you already know how to locate, build, and install code samples, you can go directly to the section testing
, and read about how to configure and run the code sample.
Before you run this coding sample, make sure that the following conditions are met:
- The sample package and its associated sample data must first be installed to the local hard disk. For more information, see the Books Online topic, "Installing and Compiling Integration Services Coding Samples."
- Microsoft Visual Studio 2005
- Microsoft SQL Server 2005 Integration Services
If the code sample was installed to the default location, the sample is located in the following directory:
C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\IncrementTask Sample
The C# solution for the code sample is located in the CS directory, and the Visual Basic solution is located in the VB directory.
For information about the two-step process required to install the samples, see Installing Samples
. To obtain the latest version of the samples, including new samples released after the original release of SQL Server 2005, see SQL Server 2005 Samples and Sample Databases (April 2006)
Building the Sample
If you have not already generated a strong name key file in the Samples
folder, use the following procedure to generate this key file. The sample projects are configured on the Signing
tab of the Project Properties
dialog box to sign assemblies at build time with this key file.
To generate a strong name key file
- To open a Microsoft Visual Studio 2005 command prompt, click Start, point to All Programs, point to Microsoft Visual Studio 2005, point to Visual Studio Tools, and then click Visual Studio 2005 Command Prompt.- or -To open a Microsoft .NET Framework command prompt, click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.
- At the command prompt, use the change directory (CD) command to change the current folder of the Command Prompt window to the Samples folder. The key file that you create in this folder will be used by all Microsoft SQL Server 2005 code samples. Note: To determine the folder where samples are located, click Start, point to All Programs, point to Microsoft SQL Server 2005, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <systemdrive>_:\Program Files\Microsoft SQL Server\90\Samples.
- At the command prompt, run the following command to generate the key file:sn -k SampleKey.snk Important: For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.
- You will need the public key token from the key file in a subsequent step. To obtain the public key token, first extract the public key from the key file by running the following command at the command prompt:sn -p SampleKey.snk SampleKeyPublic.snk
- Display the public key token by running the following command at the command prompt: sn -t SampleKeyPublic.snk
- Copy the public key token to the clipboard or save for later use.
To build the sample
- Open Microsoft Visual Studio 2005.
- From the File | Open menu, click Project and open the IncrementTask.sln from the desired Samples directory, which is CS for C# language, or VB for Visual Basic.
- In the Solution Explorer, select the IncrementTask.cs or IncrementTask.vb code.
- In the code, locate the DtsTask attribute. In that line of code, replace the existing value of the public key token in the* UITypeName* attribute property in the IncrementTask.cs. The alphanumeric value after "PublicKeyToken =" should be replaced with the one displayed in the previous step.
- Click Build / Build IncrementTask on the menu to build the DLL for the project.
Installing the Sample
This sample is provided in both Visual Basic and C#. To distinguish the assemblies for each version of the sample, the name of the output assembly has CS or VB appended. After successfully building the component, follow these steps in order to add it as a Control Flow task in Business Intelligence Development Studio.
To install the component into the Global Assembly Cache by dragging and dropping the assembly
- Copy the assembly (IncrementTaskCS.dll or IncrementTaskVB.dll) to the folder located at %system%\Program Files\Microsoft SQL Server\90\DTS\Tasks.
- Using a second window, open the directory for the global assembly cache at %system%\assembly. For most computers, this will be C:\Windows\assembly.
- Select the assembly in the first window, and then drag it into the window that contains the assembly folder.
To install the component into the Global Assembly Cache by using gacutil.exe
- Open a Command Prompt window.
- Type the following command to install the C# version of the component and the user interface into the global assembly cache: gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\IncrementTask Sample\CS\bin\Debug\IncrementTaskCS.dll"
- Type the following command to install the Visual Basic version of the component and the user interface into the global assembly cache:** gacutil.exe -iF " C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Programming Samples\Control Flow\IncrementTask Sample\VB\bin\Debug\IncrementTaskVB.dll" Note For simplicity, the user interface for this sample has been put in the same project as the task code; therefore, copying the DLL into the assembly directory is all that is required. If you decide to code the user interface in a different project, you must add the DLL that contains the user interface to the global assembly cache, in addition to the DLL that contains the code. Only the code must be compiled into a specific directory.
Testing the Sample
You can test the sample task in SSIS Designer by following these steps.
To use the sample in Business Intelligence Development Studio
- Open Business Intelligence Development Studio.
- From the menu, click File / New / Project.
- From the New Project dialog box, in the Project Types, click Business Intelligence Projects and in the right pane, click Integration Services Project.
- In the Name box, type IncrementTask as the name for the new project.
- In the Location box, select the location you want to save the file to. Click OK.
- From the Solution Explorer dialog box, double-click Package.dtsx.
- In the Control Flow Items toolbox, right-click anywhere in the area where Control Flow Items are listed. Click Choose Items.
- Click the SSIS Control Flow Items tab. Scroll down and select the IncrementTaskCS or IncrementTaskVB item. Click OK. The IncrementTask task should now be visible in the Control Flow Items toolbox.
- Add the IncrementTask to the control flow surface of the package by double-clicking the task, or dragging the task onto the Control Flow surface.
- After the task is on the design surface, double-click the task to open the editor. Set the Loop Count to 5 and the Increment Value to 1.
- Click Done.
- Run the package.
- When the package is finished, view the Execution Results tab in the designer.
| Release || History |
| 5 December 2005 || Changed content: Added steps for creating key. |
© 2007 Microsoft Corporation. All rights reserved.