Upgrading the Version of a Data Flow Component
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.
Note
When you recompile a custom component for a new version of Integration Services, you do not have to change the value of the CurrentVersion property if the component's properties have not changed.
Example
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 version 1.0 of the fictitious component, this property was named RaiseErrorOnInvalidValue
and accepted a Boolean value of true or false. In version 2.0 of the fictitious component, 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.
Note
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.
Imports Microsoft.SqlServer.Dts.Pipeline
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
<DtsPipelineComponent(ComponentType:=ComponentType.Transform, CurrentVersion:=2)> _
Public Class PerformUpgrade
Inherits PipelineComponent
' Define the set of possible values for the new custom property.
Private Enum InvalidValueHandling
Ignore
FireInformation
FireWarning
FireError
End Enum
Public Overloads Overrides Sub PerformUpgrade(ByVal pipelineVersion As Integer)
' Obtain the current component version from the attribute.
Dim componentAttribute As DtsPipelineComponentAttribute = _
CType(Attribute.GetCustomAttribute(Me.GetType, _
GetType(DtsPipelineComponentAttribute), False), _
DtsPipelineComponentAttribute)
Dim currentVersion As Integer = 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 Then
' Get the current value of the old custom property, RaiseErrorOnInvalidValue,
' and then remove the property from the custom property collection.
Dim oldValue As Boolean = False
Try
Dim oldProperty As IDTSCustomProperty100 = _
ComponentMetaData.CustomPropertyCollection("RaiseErrorOnInvalidValue")
oldValue = CType(oldProperty.Value, Boolean)
ComponentMetaData.CustomPropertyCollection.RemoveObjectByIndex("RaiseErrorOnInvalidValue")
Catch ex As Exception
' If the old custom property is not available, ignore the error.
End Try
' Set the value of the new custom property, InvalidValueHandling,
' by using the appropriate enumeration value.
Dim newProperty As IDTSCustomProperty100 = _
ComponentMetaData.CustomPropertyCollection("InvalidValueHandling")
If oldValue = True Then
newProperty.Value = InvalidValueHandling.FireError
Else
newProperty.Value = InvalidValueHandling.Ignore
End If
End If
' Update the saved component version metadata to the current version.
ComponentMetaData.Version = currentVersion
End Sub
End Class
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
{
IDTSCustomProperty100 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.
IDTSCustomProperty100 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;
}
}
Stay Up to Date with Integration Services
For the latest downloads, articles, samples, and videos from Microsoft, as well as selected solutions from the community, visit the Integration Services page on MSDN:
Visit the Integration Services page on MSDN
For automatic notification of these updates, subscribe to the RSS feeds available on the page.