I am creating an SSIS package programatically in vb.net version 4.0 for SQL server 2008 R2 and I am having difficulty creating an Execute SQL Task. The code for the task is as follows:
Public Sub CreateExecuteSQLTask()
Dim TaskHost = DirectCast(Package.Executables.Add("Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask, Microsoft.SqlServer.SQLTask, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"), Microsoft.SqlServer.Dts.Runtime.TaskHost)
TaskHost.Name = "Task"
TaskHost.Description = "Task Description"
Dim ExecuteSQLTask As Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask
ExecuteSQLTask = DirectCast(TaskHost.InnerObject, ExecuteSQLTask)
ExecuteSQLTask.Connection = DestinationDBConnectionManager.ID
ExecuteSQLTask.SqlStatementSource = "Select * from Employees"
End Sub
When the above code runs I get the following exception when casting the TaskHost to an Execute SQL command.
Unable to cast COM object of type 'System.__ComObject' to class type 'Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
I have used the following article as a reference:
Please advise how I can get past this issue.