Home All Groups Group Topic Archive Search About

Error automating DTS Package from VB6 to VB.NET

Author
21 Dec 2005 5:00 AM
John
I am trying to convert a VB6 SQL 2000 created code into VB.NET.  Everything
complies fine but then I get this error message:

An unhandled exception of type 'System.InvalidCastException' occurred in
Project1.exe

Additional information: QueryInterface for interface DTS.CustomTask failed.

This is the portion of the code that it is breaking on:
I found 2 ways to do this but both ways are giving me the same error message

Way #1:
    Public Sub Task_Sub1(ByVal goPackage As DTS.Package2)

        Dim oTask As DTS.Task
        Dim oLookup As DTS.Lookup

        Dim oCustomTask1 As DTS.DataPumpTask2
        oTask = CType(goPackage, DTS.Package2).Tasks.New("DTSDataPumpTask")
        oTask = goPackage.Tasks.New("DTSDataPumpTask")
        oCustomTask1 = oTask.CustomTask

Way #2:

    Public Sub Task_Sub1(ByVal goPackage As Object)

        Dim oTask As DTS.Task
        Dim oLookup As DTS.Lookup

        Dim oCustomTask1 As DTS.DataPumpTask2
        oTask = CType(goPackage, DTS.Package2).Tasks.New("DTSDataPumpTask")
        oCustomTask1 = oTask.CustomTask

If anyone has an idea on what I need to change in the code I would greatly
appreciate it.

Thanks in advance

AddThis Social Bookmark Button