Donny Ma


Has anyone done this I can't find anything in the documentation
that describes this. The closest I get is to the InnerObject property
of the TaskHost class. There is an example of programming a bulk
insert task. But I can't find anything on programmatically setting
the column mappings (source to dest) of a simple data flow task. Any
help is appreciated!




Re: How to programmatically set column mappings of a simple data flow task?

Jamie Thomson


Donny,

This should get you past your initial problem of getting past the innerObject:

Iterate over a package programatically

(http://blogs.conchango.com/jamiethomson/archive/2007/03/06/SSIS_3A00_-Iterate-over-a-package-programatically.aspx)

After that you should go here:

Building Packages Programmatically

(http://msdn2.microsoft.com/en-us/library/ms345167.aspx)

and here:

Connecting Data Flow Components Programmatically

(http://msdn2.microsoft.com/en-us/library/ms136086.aspx)

-Jamie







Re: How to programmatically set column mappings of a simple data flow task?

Donny Ma

Thanks, Jamie, that helped a lot. I have a further question, though. I want to make a script task that will programmatically set the mappings in the subsequent data flow task. That is, I am writing this code in the package, not separate code to create the package. How do I reference the data flow task from within a script task That is, how do I set e in the following code (and actually, the Mainpipe class does not seem to be recognized by the IDE): Thanks for your help!

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.SqlServer.Dts.Pipeline

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Public Class ScriptMain

' The execution engine calls this method when the task executes.

' To access the object model, use the Dts object. Connections, variables, events,

' and logging features are available as static members of the Dts class.

' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

'

' To open Code and Text Editor Help, press F1.

' To open Object Browser, press Ctrl+Alt+J.

Public Sub Main()

'

' Add your code here

'

Dim e As Executable

Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _

CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)

Dim dataflowtask As Mainpipe

Dts.TaskResult = Dts.Results.Success

End Sub

End Class






Re: How to programmatically set column mappings of a simple data flow task?

Jamie Thomson

Donny Ma wrote:

Thanks, Jamie, that helped a lot. I have a further question, though. I want to make a script task that will programmatically set the mappings in the subsequent data flow task.

Can't be done. Period.

Read more from the father of SSIS, Kirk Haselden:

Self Modifying Packages in SSIS

(http://sqljunkies.com/WebLog/knight_reign/comments/17731.aspx)

-Jamie






Re: How to programmatically set column mappings of a simple data flow task?

Donny Ma

Thanks for the clarification about not being able to self-modify a package. I am following Kirk's example of loading a package and then trying to set its properties. I'm now running into the problem that "Mainpipe" is not a recognized type. I have the imports statements from the help link you gave me earlier. Is there something else I am missing We're getting closer to the answer, and thanks for your help!

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.SqlServer.Dts.Pipeline

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Public Class ScriptMain

'

Public Sub Main()

'

'

Dim app As Microsoft.SqlServer.Dts.Runtime.Application = New Application()

Dim package As Microsoft.SqlServer.Dts.Runtime.Package = _

app.LoadPackage("c:\systime\ExcelOut\ExcelOut\ExcelOutDo.dtsx", Nothing)

Dim e As Executable = package.Executables(0)

Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _

CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)

Dim dataFlowTask As MainPipe = CType(thMainPipe.InnerObject, MainPipe)

Console.WriteLine(dataFlowTask.pathcollection.count)

Dts.TaskResult = Dts.Results.Success

End Sub

End Class





Re: How to programmatically set column mappings of a simple data flow task?

Jamie Thomson

Sorry Donny. it looks good to me! If you find the problem reply and let me know!






Re: How to programmatically set column mappings of a simple data flow task?

jwelch

I think I might have answered this in your other thread (or it may have been someone else's entirely) - did you add a reference to the Microsoft.SQLServer. DTSPipelineWrap to the project