title: How to use SSIS API to read a package and determine task sequence from code (PrecedenceConstraints)
body: <p>I am writing aprogram which uses the Microsoft.SqlServer.Dts.Runtime library to load a package from XML. Currently, I am extracting all of the connections and tasks but I am not currently capturing the precedence sequence.</p>
  
  <p>I used the following short debug snippet to dance around the objects and properties that looked like they contained this information</p>
  
  <pre><code>public void Scan(string tempPath)
      {    
          XmlDocument packageXml = new XmlDocument();
          packageXml.Load(tempPath);
          IDTSEvents events = new SsisEventSupport();
          package = new Microsoft.SqlServer.Dts.Runtime.Package { PackagePassword = this.packagePassword };
          package.LoadFromXML(packageXml, events);
  
          foreach (var precedenceConstraint in package.PrecedenceConstraints)
          {
              //precedenceConstraint.;
              Microsoft.SqlServer.Dts.Runtime.TaskHost constrainedExecutable = (Microsoft.SqlServer.Dts.Runtime.TaskHost)precedenceConstraint.ConstrainedExecutable;
              string taskName = constrainedExecutable.Name;
              string taskId = constrainedExecutable.ID;
              string precedenceConstraintId = precedenceConstraint.ID;
  
              Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask executeSqlTask = (Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask)constrainedExecutable.InnerObject;
  
          }
  </code></pre>
  
  <p>constrainedExecutable.ID is giving me the ID of the object that is being constrained but <strong>I can't figure out the ID of the object that is constraining it!</strong>   precedenceConstraint.ID is the ID of the constraint itself, not the ID of what is constraining the object identified by constrainedExecutable.ID.</p>
  
  <p>I've search and searched but can't seem to find it. If you need an example, I created a simple package with 3 Execute SQL Tasks with no Connections. The execution flow is as follows:</p>
  
  <pre><code>Perform  1 =&gt; Do Step 2 =&gt; Another Step
  </code></pre>
  
  <p>I've opened up the SQL 2008 dtsx file and cleaned up the file leaving mostly the relevant xml. In the first example, the first SSIS constraint IDE arrow between "Perform Step 1" and "Do Step 2" has an ID of 9726771C-E514-4D2D-B586-BC49D82A944E (precedenceConstraint.ID), the ID of the arrow/precident itself. The value of constrainedExecutable.ID is the ID of the constrained task, "Do Step 2", 06B8BB21-5604-4A62-BD2F-9BBA7D1CA1ED. Looking at the XML, I know that the ID of the of the preceeding task is AEFFD93C-4C6D-4388-9FD5-603F6608A76C}, the ID of the first task, "Perform 1", but <strong>how do I get the value of this ID from code?</strong></p>
  
  <p><img src="https://i.stack.imgur.com/iEdVH.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/1LaKu.png" alt="enter image description here">
        </p>
  
  <pre><code>  &lt;DTS:Executable DTS:ExecutableType="Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask, Microsoft.SqlServer.SQLTask, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" DTS:ThreadHint="0"&gt;
    &lt;DTS:Property DTS:Name="TaskContact"&gt;Execute SQL Task; Microsoft Corporation; Microsoft SQL Server 2008 R2; © 2007 Microsoft Corporation; All Rights Reserved;http://www.microsoft.com/sql/support/default.asp;1&lt;/DTS:Property&gt; 
  
    &lt;DTS:Property DTS:Name="ObjectName"&gt;Perform 1&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="DTSID"&gt;{AEFFD93C-4C6D-4388-9FD5-603F6608A76C}&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Description"&gt;Execute SQL Task&lt;/DTS:Property&gt; 
  
      &lt;DTS:ObjectData&gt;
          &lt;SQLTask:SqlTaskData SQLTask:Connection="" SQLTask:TimeOut="0" SQLTask:IsStoredProc="False" SQLTask:BypassPrepare="True" SQLTask:SqlStmtSourceType="DirectInput" SQLTask:SqlStatementSource="" SQLTask:CodePage="1252" SQLTask:ResultType="ResultSetType_None" xmlns:SQLTask="www.microsoft.com/sqlserver/dts/tasks/sqltask" /&gt; 
      &lt;/DTS:ObjectData&gt;  
    &lt;/DTS:Executable&gt;
  
  
   &lt;DTS:Executable DTS:ExecutableType="Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask, Microsoft.SqlServer.SQLTask, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" DTS:ThreadHint="0"&gt;
    &lt;DTS:Property DTS:Name="LoggingMode"&gt;0&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="FilterKind"&gt;1&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="EventFilter" DTS:DataType="8" /&gt; 
    &lt;/DTS:LoggingOptions&gt;
        &lt;DTS:Property DTS:Name="ObjectName"&gt;Do Step 2&lt;/DTS:Property&gt; 
        &lt;DTS:Property DTS:Name="DTSID"&gt;{06B8BB21-5604-4A62-BD2F-9BBA7D1CA1ED}&lt;/DTS:Property&gt; 
        &lt;DTS:Property DTS:Name="Description"&gt;Execute SQL Task&lt;/DTS:Property&gt; 
  
       &lt;DTS:ObjectData&gt;
        &lt;SQLTask:SqlTaskData SQLTask:Connection="" SQLTask:TimeOut="0" SQLTask:IsStoredProc="False" SQLTask:BypassPrepare="True" SQLTask:SqlStmtSourceType="DirectInput" SQLTask:SqlStatementSource="" SQLTask:CodePage="1252" SQLTask:ResultType="ResultSetType_None" xmlns:SQLTask="www.microsoft.com/sqlserver/dts/tasks/sqltask" /&gt; 
       &lt;/DTS:ObjectData&gt;
  
  &lt;/DTS:Executable&gt;
  
  - &lt;DTS:Executable DTS:ExecutableType="Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.ExecuteSQLTask, Microsoft.SqlServer.SQLTask, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" DTS:ThreadHint="0"&gt;
    &lt;DTS:Property DTS:Name="ExecutionLocation"&gt;0&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="ExecutionAddress" /&gt; 
    &lt;DTS:Property DTS:Name="TaskContact"&gt;Execute SQL Task; Microsoft Corporation; Microsoft SQL Server 2008 R2; © 2007 Microsoft Corporation; All Rights Reserved;http://www.microsoft.com/sql/support/default.asp;1&lt;/DTS:Property&gt; 
  
    &lt;DTS:Property DTS:Name="ObjectName"&gt;Another Step&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="DTSID"&gt;{2B89143B-4828-4AFA-9B5A-FAE0DB17880B}&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Description"&gt;Execute SQL Task&lt;/DTS:Property&gt;   
   &lt;DTS:ObjectData&gt;
    &lt;SQLTask:SqlTaskData SQLTask:Connection="" SQLTask:TimeOut="0" SQLTask:IsStoredProc="False" SQLTask:BypassPrepare="True" SQLTask:SqlStmtSourceType="DirectInput" SQLTask:SqlStatementSource="" SQLTask:CodePage="1252" SQLTask:ResultType="ResultSetType_None" xmlns:SQLTask="www.microsoft.com/sqlserver/dts/tasks/sqltask" /&gt; 
    &lt;/DTS:ObjectData&gt;
    &lt;/DTS:Executable&gt;
  
  - &lt;DTS:PrecedenceConstraint&gt;
    &lt;DTS:Property DTS:Name="Value"&gt;0&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="EvalOp"&gt;2&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="LogicalAnd"&gt;-1&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Expression" /&gt; 
    &lt;DTS:Executable IDREF="{AEFFD93C-4C6D-4388-9FD5-603F6608A76C}" DTS:IsFrom="-1" /&gt; 
    &lt;DTS:Executable IDREF="{06B8BB21-5604-4A62-BD2F-9BBA7D1CA1ED}" DTS:IsFrom="0" /&gt; 
    &lt;DTS:Property DTS:Name="ObjectName"&gt;Constraint&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="DTSID"&gt;{9726771C-E514-4D2D-B586-BC49D82A944E}&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Description" /&gt; 
    &lt;DTS:Property DTS:Name="CreationName" /&gt; 
    &lt;/DTS:PrecedenceConstraint&gt;
  - &lt;DTS:PrecedenceConstraint&gt;
    &lt;DTS:Property DTS:Name="Value"&gt;0&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="EvalOp"&gt;2&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="LogicalAnd"&gt;-1&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Expression" /&gt; 
    &lt;DTS:Executable IDREF="{06B8BB21-5604-4A62-BD2F-9BBA7D1CA1ED}" DTS:IsFrom="-1" /&gt; 
    &lt;DTS:Executable IDREF="{2B89143B-4828-4AFA-9B5A-FAE0DB17880B}" DTS:IsFrom="0" /&gt; 
    &lt;DTS:Property DTS:Name="ObjectName"&gt;Constraint 1&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="DTSID"&gt;{42D509E8-4856-491B-A1D7-A30E4AA82B77}&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Description" /&gt; 
    &lt;DTS:Property DTS:Name="CreationName" /&gt; 
    &lt;/DTS:PrecedenceConstraint&gt;
    &lt;DTS:Property DTS:Name="ObjectName"&gt;Package1&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="DTSID"&gt;{D0AC46B8-4D38-41AB-830F-93E195B5300D}&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Description" /&gt; 
    &lt;DTS:Property DTS:Name="CreationName"&gt;SSIS.Package.2&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="DisableEventHandlers"&gt;0&lt;/DTS:Property&gt; 
  
    &lt;DTS:Property DTS:Name="PackageVariableValue" DTS:DataType="8"&gt;&lt;Package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" xmlns:dwd="http://schemas.microsoft.com/DataWarehouse/Designer/1.0"&gt;&lt;dwd:DtsControlFlowDiagram&gt;&lt;dwd:BoundingTop&gt;1000&lt;/dwd:BoundingTop&gt;&lt;dwd:Layout&gt;&lt;dds&gt; &lt;diagram fontclsid="{0BE35203-8F91-11CE-9DE3-00AA004BB851}" mouseiconclsid="{0BE35204-8F91-11CE-9DE3-00AA004BB851}" defaultlayout="Microsoft.DataWarehouse.Layout.GraphLayout100" defaultlineroute="Microsoft.DataWarehouse.Layout.GraphLayout100" version="7" nextobject="14" scale="100" pagebreakanchorx="0" pagebreakanchory="0" pagebreaksizex="0" pagebreaksizey="0" scrollleft="0" scrolltop="4263" gridx="150" gridy="150" marginx="1000" marginy="1000" zoom="100" x="21616" y="8281" backcolor="15334399" defaultpersistence="2" PrintPageNumbersMode="3" PrintMarginTop="0" PrintMarginBottom="635" PrintMarginLeft="0" PrintMarginRight="0" marqueeselectionmode="1" mousepointer="0" snaptogrid="0" autotypeannotation="1" showscrollbars="0" viewpagebreaks="0" donotforceconnectorsbehindshapes="1" backpictureclsid="{00000000-0000-0000-0000-000000000000}"&gt; &lt;font&gt; &lt;ddsxmlobjectstreamwrapper binary="01010000900180380100065461686f6d61" /&gt; &lt;/font&gt; &lt;mouseicon&gt; &lt;ddsxmlobjectstreamwrapper binary="6c74000000000000" /&gt; &lt;/mouseicon&gt; &lt;/diagram&gt; &lt;layoutmanager&gt; &lt;ddsxmlobj /&gt; &lt;/layoutmanager&gt; &lt;ddscontrol controlprogid="DdsShapes.DdsObjectManagedBridge.2" tooltip="No connection manager is specified. " left="0" top="7654" logicalid="6" controlid="1" masterid="0" hint1="0" hint2="0" width="3598" height="1164" noresize="0" nomove="0" nodefaultattachpoints="0" autodrag="1" usedefaultiddshape="1" selectable="1" showselectionhandles="1" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0"&gt; &lt;control&gt; &lt;ddsxmlobjectstreaminitwrapper binary="000800000e0e00008c040000" /&gt; &lt;/control&gt; &lt;layoutobject&gt; &lt;ddsxmlobj&gt; &lt;property name="LogicalObject" value="{06B8BB21-5604-4A62-BD2F-9BBA7D1CA1ED}" vartype="8" /&gt; &lt;property name="ShowConnectorSource" value="0" vartype="2" /&gt; &lt;/ddsxmlobj&gt; &lt;/layoutobject&gt; &lt;shape groupshapeid="0" groupnode="0" /&gt; &lt;/ddscontrol&gt; &lt;ddscontrol controlprogid="DdsShapes.DdsObjectManagedBridge.2" tooltip="No connection manager is specified. " left="978" top="5300" logicalid="7" controlid="2" masterid="0" hint1="0" hint2="0" width="3598" height="1164" noresize="0" nomove="0" nodefaultattachpoints="0" autodrag="1" usedefaultiddshape="1" selectable="1" showselectionhandles="1" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0"&gt; &lt;control&gt; &lt;ddsxmlobjectstreaminitwrapper binary="000800000e0e00008c040000" /&gt; &lt;/control&gt; &lt;layoutobject&gt; &lt;ddsxmlobj&gt; &lt;property name="LogicalObject" value="{AEFFD93C-4C6D-4388-9FD5-603F6608A76C}" vartype="8" /&gt; &lt;property name="ShowConnectorSource" value="0" vartype="2" /&gt; &lt;/ddsxmlobj&gt; &lt;/layoutobject&gt; &lt;shape groupshapeid="0" groupnode="0" /&gt; &lt;/ddscontrol&gt; &lt;ddscontrol controlprogid="MSDDS.Polyline" left="1400" top="6065" logicalid="8" controlid="3" masterid="0" hint1="0" hint2="0" width="1777" height="2089" noresize="0" nomove="0" nodefaultattachpoints="1" autodrag="0" usedefaultiddshape="0" selectable="1" showselectionhandles="0" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0"&gt; &lt;control&gt; &lt;ddsxmlobj&gt; &lt;polyline endtypedst="3" endtypesrc="1" usercolor="32768" linestyle="0" linerender="2" customendtypedstid="0" customendtypesrcid="0" adornsvisible="1" /&gt; &lt;/ddsxmlobj&gt; &lt;/control&gt; &lt;layoutobject&gt; &lt;ddsxmlobj&gt; &lt;property name="LogicalObject" value="{9726771C-E514-4D2D-B586-BC49D82A944E}" vartype="8" /&gt; &lt;property name="Virtual" value="0" vartype="11" /&gt; &lt;property name="VisibleAP" value="0" vartype="3" /&gt; &lt;/ddsxmlobj&gt; &lt;/layoutobject&gt; &lt;connector lineroutestyle="Microsoft.DataWarehouse.Layout.GraphLayout100" sourceid="2" destid="1" sourceattachpoint="7" destattachpoint="6" segmenteditmode="0" bendpointeditmode="0" bendpointvisibility="2" relatedid="0" virtual="0"&gt; &lt;point x="2777" y="6464" /&gt; &lt;point x="2777" y="7059" /&gt; &lt;point x="1799" y="7059" /&gt; &lt;point x="1799" y="7654" /&gt; &lt;/connector&gt; &lt;/ddscontrol&gt; &lt;ddscontrol controlprogid="DdsShapes.DdsObjectManagedBridge.2" tooltip="No connection manager is specified. " left="740" top="9930" logicalid="9" controlid="4" masterid="0" hint1="0" hint2="0" width="3598" height="1164" noresize="0" nomove="0" nodefaultattachpoints="0" autodrag="1" usedefaultiddshape="1" selectable="1" showselectionhandles="1" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0"&gt; &lt;control&gt; &lt;ddsxmlobjectstreaminitwrapper binary="000800000e0e00008c040000" /&gt; &lt;/control&gt; &lt;layoutobject&gt; &lt;ddsxmlobj&gt; &lt;property name="LogicalObject" value="{2B89143B-4828-4AFA-9B5A-FAE0DB17880B}" vartype="8" /&gt; &lt;property name="ShowConnectorSource" value="0" vartype="2" /&gt; &lt;/ddsxmlobj&gt; &lt;/layoutobject&gt; &lt;shape groupshapeid="0" groupnode="0" /&gt; &lt;/ddscontrol&gt; &lt;ddscontrol controlprogid="MSDDS.Polyline" left="1400" top="8419" logicalid="10" controlid="5" masterid="0" hint1="0" hint2="0" width="1539" height="2011" noresize="0" nomove="0" nodefaultattachpoints="1" autodrag="0" usedefaultiddshape="0" selectable="1" showselectionhandles="0" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0"&gt; &lt;control&gt; &lt;ddsxmlobj&gt; &lt;polyline endtypedst="3" endtypesrc="1" usercolor="32768" linestyle="0" linerender="2" customendtypedstid="0" customendtypesrcid="0" adornsvisible="1" /&gt; &lt;/ddsxmlobj&gt; &lt;/control&gt; &lt;layoutobject&gt; &lt;ddsxmlobj&gt; &lt;property name="LogicalObject" value="{42D509E8-4856-491B-A1D7-A30E4AA82B77}" vartype="8" /&gt; &lt;property name="Virtual" value="0" vartype="11" /&gt; &lt;property name="VisibleAP" value="0" vartype="3" /&gt; &lt;/ddsxmlobj&gt; &lt;/layoutobject&gt; &lt;connector lineroutestyle="Microsoft.DataWarehouse.Layout.GraphLayout100" sourceid="1" destid="4" sourceattachpoint="7" destattachpoint="6" segmenteditmode="0" bendpointeditmode="0" bendpointvisibility="2" relatedid="0" virtual="0"&gt; &lt;point x="1799" y="8818" /&gt; &lt;point x="1799" y="9374" /&gt; &lt;point x="2539" y="9374" /&gt; &lt;point x="2539" y="9930" /&gt; &lt;/connector&gt; &lt;/ddscontrol&gt; &lt;/dds&gt;&lt;/dwd:Layout&gt;&lt;dwd:PersistedViewPortTop&gt;4263&lt;/dwd:PersistedViewPortTop&gt;&lt;/dwd:DtsControlFlowDiagram&gt;&lt;/Package&gt;&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Namespace"&gt;dts-designer-1.0&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="ObjectName"&gt;package-diagram&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="DTSID"&gt;{9517A3EC-AB7A-4B57-A78B-33F2E4568DCF}&lt;/DTS:Property&gt; 
    &lt;DTS:Property DTS:Name="Description" /&gt; 
    &lt;DTS:Property DTS:Name="CreationName" /&gt; 
    &lt;/DTS:PackageVariable&gt;
    &lt;/DTS:Executable&gt;
  </code></pre>
  
  <p>I wish I could go straight to offering a big bounty for this one, as I suspect that that's where it will end.</p>