TaskHost.Properties 属性

定义

获取包含与任务关联的属性的 DtsProperties 集合。

public:
 property Microsoft::SqlServer::Dts::Runtime::DtsProperties ^ Properties { Microsoft::SqlServer::Dts::Runtime::DtsProperties ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.DtsProperties Properties { get; }
member this.Properties : Microsoft.SqlServer.Dts.Runtime.DtsProperties
Public ReadOnly Property Properties As DtsProperties

属性值

一个 DtsProperties 集合。

实现

示例

下面的代码示例创建一个 XMLTaskProperties使用集合时,将设置任务的属性。 Properties建议使用集合在任何任务上设置属性。 不建议将任务强制转换为其等效类和直接设置的属性。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
using Microsoft.SqlServer.Dts.Tasks.XMLTask;  

namespace XMLTask_API  
{  
    class Program  
        {  
        static void Main(string[] args)  
                {  
                        // Set up the objects and tasks.  
                        Package pkg = new Package();  
                        Executable exec1 = pkg.Executables.Add("STOCK:XMLTask");  
                        TaskHost th = exec1 as TaskHost;  
                        // You can cast the InnerObject to the specific task,  
                        // but it is advised that you work with tasks through  
                        //  the TaskHost and its Properties.  
                        // XMLTask myTask = th.InnerObject as XMLTask;  

                        // Create a variable and a FILE connection manager to books.xml.  
                        Variable resultVar = pkg.Variables.Add("resultVariable", false, "", "Variable for the result");  
                        ConnectionManager connMgr = pkg.Connections.Add("FILE");  
                        connMgr.Name = "XMLConnectionManager";  
                        // The file, Books.xml, is stored on the C:\ drive.  
                        connMgr.ConnectionString = @"c:\books.xml";  

                        // Set the XMLTask properties using the TaskHost.Properties.  
                        // The first property to set is the OperationType. Depending on the  
                        // OperationType, different properties are valid.  
                        // The operation type in this example is VALIDATE.  
                        th.Properties["OperationType"].SetValue(th, DTSXMLOperation.Validate);  
                        th.Properties["SourceType"].SetValue(th, DTSXMLSourceType.FileConnection);  
                        th.Properties["Source"].SetValue(th, connMgr.Name);  
                        th.Properties["OverwriteDestination"].SetValue(th, true);  
                        th.Properties["SaveOperationResult"].SetValue(th, true);  
                        th.Properties["DestinationType"].SetValue(th, DTSXMLSaveResultTo.Variable);  
                        th.Properties["Destination"].SetValue(th, resultVar.Name);  
                        th.Properties["SecondOperandType"].SetValue(th, DTSXMLSourceType.DirectInput);  
                        th.Properties["SecondOperand"].SetValue(th, "<x></x>");  
                        th.Properties["ValidationType"].SetValue(th, DTSXMLValidationType.DTD);  
                        th.Properties["FailOnValidationFaile"].SetValue(th, true);  
                        DTSExecResult valResults = pkg.Validate(pkg.Connections, pkg.Variables, null, null);  
                        Console.WriteLine("RESULTS: {0}", valResults);  
                }  
        }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.XMLTask  

Class Program  
    Shared Sub Main(ByVal args() As String)  
        ' Set up the objects and tasks.  
        Dim pkg As New Package()  
        Dim exec1 As Executable = pkg.Executables.Add("STOCK:XMLTask")  
        Dim th As TaskHost = TryCast(exec1, TaskHost)  
        ' You can cast the InnerObject to the specific task,  
        ' but it is advised that you work with tasks through  
        '  the TaskHost and its Properties.  
        ' XMLTask myTask = th.InnerObject as XMLTask;  

        ' Create a variable and a FILE connection manager to books.xml.  
        Dim resultVar As Variable = pkg.Variables.Add("resultVariable", False, "", "Variable for the result")  
        Dim connMgr As ConnectionManager = pkg.Connections.Add("FILE")  
        connMgr.Name = "XMLConnectionManager"  
        ' The file, Books.xml, is stored on the C:\ drive.  
        connMgr.ConnectionString = "c:\books.xml"  

        ' Set the XMLTask properties using the TaskHost.Properties.  
        ' The first property to set is the OperationType. Depending on the  
        ' OperationType, different properties are valid.  
        ' The operation type in this example is VALIDATE.  
        th.Properties("OperationType").SetValue(th, DTSXMLOperation.Validate)  
        th.Properties("SourceType").SetValue(th, DTSXMLSourceType.FileConnection)  
        th.Properties("Source").SetValue(th, connMgr.Name)  
        th.Properties("OverwriteDestination").SetValue(th, True)  
        th.Properties("SaveOperationResult").SetValue(th, True)  
        th.Properties("DestinationType").SetValue(th, DTSXMLSaveResultTo.Variable)  
        th.Properties("Destination").SetValue(th, resultVar.Name)  
        th.Properties("SecondOperandType").SetValue(th, DTSXMLSourceType.DirectInput)  
        th.Properties("SecondOperand").SetValue(th, "<x></x>")  
        th.Properties("ValidationType").SetValue(th, DTSXMLValidationType.DTD)  
        th.Properties("FailOnValidationFaile").SetValue(th, True)  
        Dim valResults As DTSExecResult = pkg.Validate(pkg.Connections, pkg.Variables, Nothing, Nothing)  
        Console.WriteLine("RESULTS: {0}", valResults)  
    End Sub  
End Class  

适用于