Readme_Creating a Custom Increment Task Sample

11/05/2008 21:36:06


This sample works only with SQL Server 2005 and SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 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.
  • Validation.
  • Execution.
  • 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.

Prerequisites

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
  • Microsoft SQL Server Integration Services

Location

If the code sample was installed to the default location, the sample is located in the following directory:
C:\Program Files\Microsoft SQL Server\100\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 Considerations for Installing SQL Server Samples and Sample Databases.

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
  1. To open a Microsoft Visual Studio command prompt, click Start, point to All Programs, point to Microsoft Visual Studio 2008, point to Visual Studio Tools, and then click Visual Studio 2008 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.
  2. 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 SQL Server code samples. Note: To determine the folder where samples are located, click Start, point to All Programs, point to Microsoft SQL Server 2008, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <drive>:\Program Files\Microsoft SQL Server\100\Samples.
  3. 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.
  4. 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
  5. Display the public key token by running the following command at the command prompt: sn -t SampleKeyPublic.snk
  6. Copy the public key token to the clipboard or save for later use.
To build the sample
  1. Open Microsoft Visual Studio 2008.
  2. 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.
  3. In the Solution Explorer, select the IncrementTask.cs or IncrementTask.vb code.
  4. 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.
  5. 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
  1. Copy the assembly (IncrementTaskCS.dll or IncrementTaskVB.dll) to the folder located at %system%\Program Files\Microsoft SQL Server\100\DTS\Tasks.
  2. Using a second window, open the directory for the global assembly cache at %system%\assembly. For most computers, this will be C:\Windows\assembly.
  3. 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
  1. Open a Command Prompt window.
  2. 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\100\Samples\Integration Services\Programming Samples\Control Flow\IncrementTask Sample\CS\IncrementTask\bin\Debug\IncrementTaskCS.dll"
  3. 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\100\Samples\Integration Services\Programming Samples\Control Flow\IncrementTask Sample\VB\IncrementTask\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
  1. Open Business Intelligence Development Studio.
  2. From the menu, click File / New / Project.
  3. From the New Project dialog box, in the Project Types, click Business Intelligence Projects and in the right pane, click Integration Services Project.
  4. In the Name box, type IncrementTask as the name for the new project.
  5. In the Location box, select the location you want to save the file to. Click OK.
  6. From the Solution Explorer dialog box, double-click Package.dtsx.
  7. In the Control Flow Items toolbox, right-click anywhere in the area where Control Flow Items are listed. Click Choose Items.
  8. 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.
  9. 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.
  10. 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.
  11. Click Done.
  12. Run the package.
  13. When the package is finished, view the Execution Results tab in the designer. © 2008 Microsoft Corporation. All rights reserved.

Last edited Aug 23, 2012 at 9:52 PM by sabottaca, version 10

Comments

No comments yet.