Sunday, February 19, 2012

Error automating SQL DTS Pkg from VB6 to VB.Net

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 advanceJohn,
Try with this excellent article from Gert Drapers:
http://www.sqldev.net/dts/DotNETCookBook.htm.
Dejan Sarka, SQL Server MVP
Mentor
www.SolidQualityLearning.com
"John" <John@.discussions.microsoft.com> wrote in message
news:B830B251-9289-4510-9ED8-6165AB2A0B92@.microsoft.com...
>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
>

No comments:

Post a Comment