Export (0) Print
Expand All

Upgrading the Version of a Data Flow Component

New: 5 December 2005

Packages that were created with an older version of your component may contain metadata that is no longer valid, such as custom properties whose usage has been modified in newer versions of the component. You can override the PerformUpgrade method of the PipelineComponent base class to update the metadata previously saved in older packages to reflect the current properties of your component.

The following sample contains code from version 2.0 of a fictitious data flow component. The new version number is defined in the CurrentVersion property of the DtsPipelineComponentAttribute. The component has a property that defines how numeric values that exceed a threshold are to be handled. In prior versions of the fictitious component, this property was named RaiseErrorOnInvalidValue and accepted a Boolean value of true or false. In version 2.0, the property has been renamed to InvalidValueHandling and accepts one of four possible values from a custom enumeration.

The overridden PerformUpgrade method in the following sample performs the following actions:

  • Gets the current version of the component.
  • Gets the value of the old custom property.
  • Removes the old property from the custom property collection.
  • Sets the value of the new custom property based on the value of the old property, if possible.
  • Sets the version metadata to the current version of the component.
ms345168.note(en-US,SQL.90).gifNote:
The data flow engine passes its own version number into the PerformUpgrade method in the pipelineVersion parameter. This parameter is not useful in version 1.0 of Integration Services, but may become useful in subsequent versions.

The sample code uses only the two enumeration values that map directly to the prior Boolean values for the custom property. Users can select the other available enumeration values through the component's custom user interface, in the Advanced Editor, or programmatically. For information on displaying enumeration values for a custom property in the Advanced Editor, see "Creating Custom Properties" in Design-time Methods of a Data Flow Component.

using System;
using Microsoft.SqlServer.Dts.Pipeline;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

[DtsPipelineComponent(ComponentType = ComponentType.Transform, CurrentVersion = 2)]
public class PerformUpgradeCS :
  PipelineComponent

  // Define the set of possible values for the new custom property.
{
  private enum InvalidValueHandling
  {
    Ignore,
    FireInformation,
    FireWarning,
    FireError
  };

  public override void PerformUpgrade(int pipelineVersion)
  {

    // Obtain the current component version from the attribute.
    DtsPipelineComponentAttribute componentAttribute = 
      (DtsPipelineComponentAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(DtsPipelineComponentAttribute), false);
    int currentVersion = componentAttribute.CurrentVersion;

    // If the component version saved in the package is less than
    //  the current version, Version 2, perform the upgrade.
    if (ComponentMetaData.Version < currentVersion)

    // Get the current value of the old custom property, RaiseErrorOnInvalidValue, 
    // and then remove the property from the custom property collection.
    {
      bool oldValue = false;
      try
      {
        IDTSCustomProperty90 oldProperty = 
          ComponentMetaData.CustomPropertyCollection["RaiseErrorOnInvalidValue"];
        oldValue = (bool)oldProperty.Value;
        ComponentMetaData.CustomPropertyCollection.RemoveObjectByIndex("RaiseErrorOnInvalidValue");
      }
      catch (Exception ex)
      {
        // If the old custom property is not available, ignore the error.
      }

      // Set the value of the new custom property, InvalidValueHandling,
      //  by using the appropriate enumeration value.
      IDTSCustomProperty90 newProperty = 
         ComponentMetaData.CustomPropertyCollection["InvalidValueHandling"];
      if (oldValue == true)
      {
        newProperty.Value = InvalidValueHandling.FireError;
      }
      else
      {
        newProperty.Value = InvalidValueHandling.Ignore;
      }

    }

    // Update the saved component version metadata to the current version.
    ComponentMetaData.Version = currentVersion;

  }

}

Community Additions

ADD
Show:
© 2014 Microsoft