XMLTask.Validate 方法

定義

驗證是否已正確設定元件。

public:
 override Microsoft::SqlServer::Dts::Runtime::DTSExecResult Validate(Microsoft::SqlServer::Dts::Runtime::Connections ^ connections, Microsoft::SqlServer::Dts::Runtime::VariableDispenser ^ variableDispenser, Microsoft::SqlServer::Dts::Runtime::IDTSComponentEvents ^ events, Microsoft::SqlServer::Dts::Runtime::IDTSLogging ^ log);
public override Microsoft.SqlServer.Dts.Runtime.DTSExecResult Validate (Microsoft.SqlServer.Dts.Runtime.Connections connections, Microsoft.SqlServer.Dts.Runtime.VariableDispenser variableDispenser, Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents events, Microsoft.SqlServer.Dts.Runtime.IDTSLogging log);
override this.Validate : Microsoft.SqlServer.Dts.Runtime.Connections * Microsoft.SqlServer.Dts.Runtime.VariableDispenser * Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents * Microsoft.SqlServer.Dts.Runtime.IDTSLogging -> Microsoft.SqlServer.Dts.Runtime.DTSExecResult
Public Overrides Function Validate (connections As Connections, variableDispenser As VariableDispenser, events As IDTSComponentEvents, log As IDTSLogging) As DTSExecResult

參數

connections
Connections

工作所使用之 Connections 的集合。

variableDispenser
VariableDispenser

用於鎖定變數的 VariableDispenser 物件。

events
IDTSComponentEvents

實作 IDTSComponentEvents 介面的物件。

log
IDTSLogging

實作 IDTSLogging 介面的物件。

傳回

DTSExecResult

DTSExecResult 列舉中的值。

範例

下列程式碼範例會建立 XMLTask 做為封裝的一部分。 建立工作之後,它會設定數個屬性,然後呼叫的 Validate 方法 Package

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;  
            XMLTask myTask = th.InnerObject as XMLTask;  

            // Create a FILE connection manager to books.xml.  
            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.  
            myTask.OperationType = DTSXMLOperation.Validate;  
            myTask.SourceType = DTSXMLSourceType.FileConnection;  
            myTask.Source = connMgr.Name;  

            DTSExecResult valResults = pkg.Validate(pkg.Connections, pkg.Variables, null, null);  
            Console.WriteLine("RESULTS: {0}", valResults);  
        }  
    }  
}  

範例輸出:

RESULTS: Success

備註

不論值為何,都可以使用這個方法 XMLTask OperationType

Validate方法會審核屬性和設定是否有不正確或不正確的設定。 方法不會觸控資料,也不會連接到資料來源來驗證連接。 但是,它可確保填入必要欄位,並包含適當的值。 經過驗證的欄位會因正在驗證的物件而有所不同。

的主要用途 Validate 是在撰寫自訂工作時。 當 Validate 設定屬性時,SSIS 設計工具會呼叫此方法,而當工作卸載至設計介面上時,它可能會多次。 但是在程式碼中, Validate 不常使用個別物件上的方法,因為建議您在 Validate Package 需要驗證物件時,在上呼叫方法。 但是,如果您在需要的情況下找出獨特的情況,就可以在個別物件上使用方法。

Validate方法會在自訂工作中覆寫,以在 SSIS 設計工具中使用時或由程式碼呼叫時,用於驗證物件。 如需撰寫自訂工作之方法的詳細資訊 Validate ,請參閱撰寫 自訂工作的程式碼。

適用於