Get parent container name?

  • I've been searching the net for a few hours trying to answer how to get the name of the parent container in a script. So far I've come up with I think two pieces to the puzzle, but can't put them together.

    So I've got the parent container GUID variable System::ParentContainerGUID which returns a string. I've also got a class in Dts called DtsContainer. Does anyone know how to instantiate a copy of this DtsContainer class with the GUID from the variable? I can't find any C# code on this subject. The DtsContainer does contain an ID attribute, but it's read only.

    Any help would be greatly appreciated!

    Edit: Here's a link to the DtsContainer class on technet. Also I'm using 2008 R2.

    -------------------------------------------------------------------------------------------------
    My SQL Server Blog

  • I don't know if this will work for you. SSIS has a system variable called Source Name that is the name of the container. Can you just pass that to your script task as a read only variable input?

  • I'm currently using System::SourceName to capture the failing task name in OnError. Unfortunately it is not available outside of the event handlers, and also does not capture the name of the container.

    If I could get the current ssis app or package object, I could loop through the containers... I think like this:

    List<DtsContainer> conContainers = new List<DtsContainer>();

    conContainers = (IDTSSequence)package

    But I'm not sure how to get the active package object of the package class. I don't want to create anything; I just want to read the .name off the current container object.

    Edit: I'm just trying to do something like this:

    string strContainerName = DtsContainer.Name; //where DtsContainer is the parent container

    -------------------------------------------------------------------------------------------------
    My SQL Server Blog

  • Upon further research I've found someone stating the SSIS framework doesn't allow access to the current active package, so my dream of getting the container name via an active object is pretty much out of the question at this point.

    I did see something interesting where a guy grabbed all the containers and their names from the pre-execute event handler at the package level. That seems like it could work. I have the GUID. I just need to translate it into a name!

    -------------------------------------------------------------------------------------------------
    My SQL Server Blog

  • If the source name is not available outside the event handlers, why not create a handler in the On Pre Execute with a script task to take the source name and set it to a user variable and then use the user variable elsewhere.

  • That is definitely an option. The only thing I didn't like about that option is I'm also going to be using this package as a template, and I don't want people on our team to forget to put that task in the pre-execute handler.

    I opted with just adding a hardcoded piece to our log start variables script task. Not even remotely happy with it, but at least it's in an obvious place for our template.

    -------------------------------------------------------------------------------------------------
    My SQL Server Blog

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply