Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Tough one - Accessing component properties of a Task Host inside an SSIS Data Flow

$
0
0
Having some issues with getting a conversion to a COM object to work right (at least I think that's my problem). 
 
We have a template SSIS package, within a PowerShell script I access that package, make changes to it, and save it out as a new package. I'm using the DTS namespace for everything, as opposed to mucking around in XML. I've been able to do a huge amount so far, such as setting variables, connection managers, and the like. 

The OLEDB Source component in the Data Flow Task is set from a variable. Once I change the variable, I need to be able to refresh the metadata associated with the control so it will update the output columns collection. Without doing that, the OutputColumnCollection shows 0 columns in the output. My ultimate goal is to dive into the OutputColumnsCollection so I can set the SortKey property on the correct key columns. 

In C#, the examples I have seen ( http://www.selectsifiso.net/?p=337 is a good example) looks something like:

CManagedComponentWrapper instance = source.Instantiate();
instance.ProvideComponentProperties();
instance.AcquireConnections(null);
instance.ReinitializeMetaData();
instance.RefreshConnections();

In my code I get a reference to the source component (the same as the variable in line 1 above). I know it is valid, because I can set other properties of it such as the name and its connection managers. So first I tried a simple:

$instance = $source.Instantiate();

Which works, or at least doesn't generate any error. But then I try the 

$instance.ProvideComponentProperties()

and get an error that the method doesn't exist. I then thought maybe I need to put a wrapper around it, so tried

$component = [System.Runtime.InteropServices.Marshal]::CreateWrapperOfType($instance, [Microsoft.SQLServer.DTS.pipeline.Wrapper.CManagedComponentWrapper])

But this gave an error "Exception calling "CreateWrapperOfType" with "2" argument(s): "The type must be __ComObject or be derived from __ComObject." even though a GetType on the $comp shows it is a ComObject.

Somehow I need to get a proper reference to this instance, but not quite sure where I'm going wrong. Any suggestions are appreciated. 

Thanks,

Robert  / @ArcaneCode

Viewing all articles
Browse latest Browse all 8583

Trending Articles