none
ReinitializeMetaData problem - SSIS custom component

    Question

  • Hey ladies and gents, got a puzzling problem I'm encountering. I'm building a custom component for SSIS that accepts an unlimited number of inputs. I decided one way to keep things clean was to make sure that there was exactly one unattached input at a time. Validate() checks to see how many unattached inputs there are and returns VS_NEEDSNEWMETADATA if the amount is not equal to one. ReinitializeMetaData() then cleans up the InputCollection. I've attached the code below for both overridden functions (you can see that I've used message boxes to help verify the code is actually doing what it is expected to do).

    I've verified that both functions work correctly, but the problem is that ReinitializeMetaData is not getting automatically called when Validate() returns VS_NEEDSNEWMETADATA. Instead, the little red error symbol appears with rollover text saying "Validation errors occurred", and if I click on the component, a window pops up saying "The component is not in a valid state. Do you want the component to fix itself automatically." Why isn't ReinitializeMetaData automatically running, and how can I fix it. All help greatly appreciated!

    public override DTSValidationStatus Validate()
            {
                /// If there is an input column that no longer exists in the Virtual input collection,
                /// return needs new meta data. The designer will then call ReinitalizeMetadata which will clean up the input collection.
                if (ComponentMetaData.AreInputColumnsValid == false)
                    return DTSValidationStatus.VS_NEEDSNEWMETADATA;

                /// The component should only have one unattached input at a time. If there are none, ReinitializeMetaData will create one.
                /// If there is more than one, ReinitializeMetaData will remove all extras.
                int unattachedInputCount = 0;
                foreach (IDTSInput100 input in ComponentMetaData.InputCollection)
                {
                    if (input.IsAttached == false)
                        unattachedInputCount++;
                }

                MessageBox.Show("You have " + unattachedInputCount.ToString() + " unattached inputs.");

                if (unattachedInputCount!=1)
                    return DTSValidationStatus.VS_NEEDSNEWMETADATA; 

                DTSValidationStatus status = base.Validate();
                return status;
            }

            public override void ReinitializeMetaData()
            {
                base.ReinitializeMetaData();

                this.ComponentMetaData.RemoveInvalidInputColumns();

                /// If there is more than one unattached input, removes all except one.
                IDTSInputCollection100 inputCollection = ComponentMetaData.InputCollection;
                int unattachedInputCount = 0;
                foreach (IDTSInput100 input in inputCollection)
                {
                    if (input.IsAttached == false)
                    {
                        unattachedInputCount++;
                        if (unattachedInputCount > 1)
                            inputCollection.RemoveObjectByID(input.ID);
                    }
                }

                /// If there are no unattached inputs, adds a new one.
                if (unattachedInputCount == 0)
                    inputCollection.New();

                /// Identifies remaining unattached inputs to verify the above has worked.
                unattachedInputCount = 0;
                foreach (IDTSInput100 input in ComponentMetaData.InputCollection)
                {
                    if (!input.IsAttached)
                        unattachedInputCount++;
                }

                MessageBox.Show("You now have " + unattachedInputCount.ToString() + " unattached inputs.");
            }
        }

    Monday, January 14, 2013 6:01 AM

Answers

  • Hey Jacob,

    Whatever the code you have written in Reinitialise metadata apart from base.Reinitiaslie put those code in Validate Function, you can achive your task easliy

    Regards

    Naveen

    • Marked as answer by Eileen Zhao Thursday, January 24, 2013 3:20 AM
    Tuesday, January 15, 2013 9:17 AM

All replies

  • ReinitializeMetaData runs after your Validate() event reporting on dirty finish.

    Arthur My Blog

    Monday, January 14, 2013 4:54 PM
    Moderator
  • My understanding is that's what it's supposed to do. But it's not actually doing that in my SSIS package. ReinitializeMetaData doesn't run automatically. I have to try to edit the component in the designer window, and select "yes" when the following message comes up: "The component is not in a valid state. Do you want the component to fix itself automatically?"
    Monday, January 14, 2013 7:37 PM
  • Hey Jacob,

    Whatever the code you have written in Reinitialise metadata apart from base.Reinitiaslie put those code in Validate Function, you can achive your task easliy

    Regards

    Naveen

    • Marked as answer by Eileen Zhao Thursday, January 24, 2013 3:20 AM
    Tuesday, January 15, 2013 9:17 AM
  • Naveen, thanks for the suggestion. I was told it was better to have ReinitializeMetaData do the fixes than to have Validate do them, but I think your solution will at least do what I need it to do. Thanks!
    Tuesday, January 15, 2013 3:10 PM