dbTalk Databases Forums  

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

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss DTS Custom Task in C#: How do I access the Package.Connections collection? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ryan Hoegg
 
Posts: n/a

Default DTS Custom Task in C#: How do I access the Package.Connections collection? - 06-30-2003 , 03:04 PM






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
http://www.isisnetworks.net

Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: DTS Custom Task in C#: How do I access the Package.Connections collection? - 07-01-2003 , 02:21 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

"Ryan Hoegg" <rhoegg (AT) isisnetworks (DOT) net> wrote

Quote:
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
http://www.isisnetworks.net



Reply With Quote
  #3  
Old   
Ryan Hoegg
 
Posts: n/a

Default Re: DTS Custom Task in C#: How do I access the Package.Connections collection? - 07-01-2003 , 12:31 PM



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

Quote:
-----Original Message-----
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


Reply With Quote
  #4  
Old   
Darren Green
 
Posts: n/a

Default Re: DTS Custom Task in C#: How do I access the Package.Connections collection? - 07-01-2003 , 01:14 PM



In article <32e001c33ff6$abaa5f40$a601280a (AT) phx (DOT) gbl>, Ryan Hoegg
<rhoegg (AT) isisnetworks (DOT) net> writes
Quote:
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.

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.Precendec eConstraint
Package.Connection.Connection

There is a better diagram in Books Online

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




Reply With Quote
  #5  
Old   
Ryan Hoegg
 
Posts: n/a

Default Re: DTS Custom Task in C#: How do I access the Package.Connections collection? - 07-01-2003 , 04:25 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

Darren Green wrote:

Quote:
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.Precendec eConstraint
Package.Connection.Connection

There is a better diagram in Books Online

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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.