all groups > sql server dts > june 2003 >
You're in the

sql server dts

group:

DTS Custom Task in C#: How do I access the Package.Connections collection?


DTS Custom Task in C#: How do I access the Package.Connections collection? rhoegg NO[at]SPAM isisnetworks.net
6/30/2003 1:04:17 PM
sql server dts:
Hello,

I would like to allow the package designer to select a configured
connection in my CustomTaskUI property page. However, I have been
unable to find a way to get from my CustomTask to its parent package
in order to access the Connections collection. I have found some
posts about using the DTSGlobalVariables static class from ActiveX
script tasks. However, I have not found a way to access this from C#.

I am using an RCW around Microsoft.SQLServer.DTSPkg80 now, as it
allowed me to properly install my custom task so that it showed up in
Enterprise Manager - DTS Designer.

I did find a couple articles about loading up the package using
LoadFromSQLServer, but I want my task to be decoupled from the package
it is used with.

If anyone has any advice, I'd appreciate it.

Thanks,
--
Ryan Hoegg
ISIS Networks
Re: DTS Custom Task in C#: How do I access the Package.Connections collection? Darren Green
7/1/2003 8:21:00 AM
I use the CustomTaskUI_Initialize call to grab a refernce to the current
task. This can be stored and passed to your form. From the task you can get
the parent, the package and then back to the connections collection.

The code is VB but the logic is the same-

Sample Custom Task Project
http://www.sqldts.com/default.aspx?6,107,284,0,0


--
Darren Green
http://www.sqldts.com

[quoted text, click to view]

Re: DTS Custom Task in C#: How do I access the Package.Connections collection? Ryan Hoegg
7/1/2003 10:31:57 AM
Hi Darren,

Thanks for the quick response. It gave me a nice kick in
the pants!

Task.Parent returns a reference to an IDTSStdObject in C#,
and when I try to cast this to a Package I get a
ClassCastException. I tried printing the GetType.FullName
but just got a __ComObject. So I think the Parent is not
a Package, but I will need to hack at it to figure out
what it is.

If you or anyone else has any idea how to get around this
roadblock, I'd appreciate it! If I figure it out first,
I'll post my solution.

--
Ryan Hoegg
ISIS Networks
http://www.isisnetworks.net

[quoted text, click to view]
Re: DTS Custom Task in C#: How do I access the Package.Connections collection? Ryan Hoegg
7/1/2003 2:25:40 PM
Thanks again Darren.

This was of course my problem. I have full access to the Package in
which my Custom Task is to be deployed now. I appreciate your help.

I just wanted to post this for any usenet archive readers who might find
it useful.

Tasks tasks = (Tasks) Task.Parent;
Package package = (Package) tasks.Parent;

In addition to the Books Online diagrams, MSDN Library has a nice Object
Model diagram to use. Not sure if its the same as the one in Books
Online.

--
Ryan Hoegg
ISIS Networks
http://www.isisnetworks.net

[quoted text, click to view]



*** Sent via Developersdex http://www.developersdex.com ***
Re: DTS Custom Task in C#: How do I access the Package.Connections collection? Darren Green
7/1/2003 7:14:31 PM
In article <32e001c33ff6$abaa5f40$a601280a@phx.gbl>, Ryan Hoegg
<rhoegg@isisnetworks.net> writes
[quoted text, click to view]

The parent of a Task is the Tasks collection. The parent of the Tasks
collection is the Package, easy when I think about properly.

I quick overview of the object model could be represented like this-

Package.Tasks.Task.CustomTask
Package.Steps.Step.PrecendeceConstraints.PrecendeceConstraint
Package.Connection.Connection

There is a better diagram in Books Online

--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

AddThis Social Bookmark Button