That’s what I twittered recently upon first opening up Release Candidate 0 of SQL Server 2008. You may remember that back in March of this year I told you about a new feature that would be appearing in a future CTP; namely that a container would provide information about its parent container. Hence if you peer into the depths of this latest release then you will discover that some new system variables have been introduced. Every container in the control-flow now has a system variable called @[System::ParentContainerGUID] scoped to it that contains, quite simply, the ID of the container’s parent container. The following screenshot shows three instances of this variable:
Why are there 3? Very simple, the package has three containers (which I have highlighted above) and each one of them has an instance of @[System::ParentContainerGUID] scoped to it. Note how the instance that is scoped to the package has an empty value – this makes sense of course because the package container does not have a parent.
Additionally, and more importantly, every eventhandler container also has a new system variable scoped to it called @[System::SourceParentGUID].
This variable contains the ID of the parent of the container that raised the event. Let me explain that in the context of the package depicted above; any eventhandler that (for example) handles an event thrown by “SEQ Inner Sequence Container” will have the ID of “SEQ Outer Sequence Container” stored within @[System::SourceParentGUID].
In the demo package depicted above I have a script task in the OnPostExecute package-scoped eventhandler that throws out a message box containing some information about the container that raised the OnPostExecute event. Here are the message boxes it threw up:
| N.B. You may want go and read my blog entry on event propagation to understand why the package-scoped eventhandler captures events raised by all three control-flow containers. |
Note how @[System::SourceParentGUID] for the event thrown by “SEQ Inner Sequence Container” contains the SourceID of “SEQ Outer Sequence Container” and also how the @[System::SourceParentGUID] for the event thrown by “SEQ Outer Sequence Container” contains the SourceID of the package container. Also note, again, how @[System::SourceParentGUID] for the package container is empty as you would expect.
If you want to run this simple demo for yourself then go ahead and download it: http://cid-550f681dad532637.skydrive.live.com/self.aspx/Public/BlogShare/20080607/SimpleParentContainerGUIDDemo%20package.zip
The package doesn’t access any external objects so you can literally drop it on your hard drive and execute it using dtexecui.exe. Note that you will need to have Release Candidate 0 of SQL Server 2008 or later installed.
Within this blog entry I’ve introduced you to the new system variables:
- @[System::SourceParentGUID]
- @[System::ParentContainerGUID]
in SQL Server 2008. In my next blog entry I’ll explain how you can make use of them.
-Jamie