Can't get taskhost.innerobject type when it's an Execute Package Task
When I loop trough the executables, I can't get the innerobject type when it's a Execute Package Task. TaskHost dtsTaskhost = (TaskHost)dtsExec; if (dtsTaskhost.InnerObject is Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask) { Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask dtsObject = (Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask)dtsTaskhost.InnerObject; } else if (dtsTaskhost.InnerObject is Microsoft.SqlServer.Dts.Tasks.FileSystemTask.FileSystemTask) { Microsoft.SqlServer.Dts.Tasks.FileSystemTask.FileSystemTask dtsObject = (Microsoft.SqlServer.Dts.Tasks.FileSystemTask.FileSystemTask)dtsTaskhost.InnerObject; } else if (dtsTaskhost.InnerObject is Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe) { MainPipe m = (MainPipe)dtsTaskhost.InnerObject; IDTSComponentMetaDataCollection100 mdc = m.ComponentMetaDataCollection; } But how do I check if the innerobject is a Execute Package Task?? When debugging, the object type is displayed as "{System.__ComObject}". Thanks in advance....
December 9th, 2010 8:30am

Can you try this: DtsProperties props = dtsTaskhost .Properties; For Each prop DtsProperty In props Console.WriteLine(" The type is: " + prop.Type.ToString()); NextArthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 9th, 2010 10:19am

Your code isn't actually looking for the execute package task. All tasks look like "ComObject", but if you ca cast them to a specific tyask type, then you have a match. That's what your code is doing already. However I'm not sure how to get a type for the Exec Pkg Task, it seems to be a native task and I cannot find the wrapper. Another approach is to check the creation name of the task host.http://www.sqlis.com | http://www.konesans.com
December 9th, 2010 10:19am

Hi Ton, You are right. The Execute Package Task is defined as "{System.__ComObject}". This means we are unable to use the InnerObject property to check if a TaskHost is an Execute Package Task. However, an Execute Package Task contains a property named "PackageName". If a task contains property "PackageName", we can consider it as Execute Package Task. Below is the code for your reference: TaskHost dtsTaskhost = (TaskHost)exec; DtsProperties dp = dtsTaskhost.Properties; Microsoft.SqlServer.Dts.Tasks.ExecutePackageTask.ExecutePackageTask execPackageTask = null; foreach (DtsProperty p in dp) { if (p.Name == "PackageName") { execPackageTask = (Microsoft.SqlServer.Dts.Tasks.ExecutePackageTask.ExecutePackageTask)dtsTaskhost.InnerObject; break; } } if (execPackageTask != null) { //Do something here. } Another possible approach is using Try Catch to convert a TaskHost to an Execute Package Task. If you have any more questions, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 1:05am

Hi Arthur, The prop.Type.ToString() only return the type of the value for a property. So, it won't work in this scenario. Thanks, Jin ChenJin Chen - MSFT
December 10th, 2010 1:08am

Thanks for your reply Jin, this was very helpfull!!! One question: Where can I find the reference to "Microsoft.SqlServer.Dts.Tasks.ExecutePackageTask.ExecutePackageTask". The only reference I found is "Microsoft.SqlServer.Dts.Tasks.Exec80PackageTask" Greetz Ton.
Free Windows Admin Tool Kit Click here and download it now
December 10th, 2010 10:18am

Never mind, it was in the GAC Right click References --> Add Reference in your C# project In Add Reference dialog select Browse page. In File Name type: %windir%\assembly\GAC_MSIL\Microsoft.SqlServer.ExecPackageTaskWrap\9.0.242.0__89845dcd8080cc91\Microsoft.SqlServer.ExecPackageTaskWrap.dll
December 10th, 2010 10:29am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics