語言

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 枚舉的數值。

範例

以下程式碼範例將 建立 XMLTask 為套件的一部分。 任務建立後,它會設定多個屬性,然後呼叫 ValidatePackage的方法。

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

備註

此方法無論值為OperationType何,均可用於 XMLTask。

此 Validate 方法會審查屬性與設定是否有不準確或錯誤設定。 此方法不會接觸資料,也不會連接資料來源來驗證連線。 然而,它確保所需欄位已被填入且包含適當的值。 被驗證的欄位會依驗證對象而異。

主要用途 Validate 是在撰寫自訂任務時。 當任務被丟到設計表面時,SSIS 設計師會呼叫此 Validate 方法,且在設定屬性時也可能多次呼叫。 然而,在程式碼中,針對個別物件的方法 Validate 並不常用,因為建議在需要驗證物件時呼叫該 Validate 方法 Package 。 不過,如果你遇到特殊情況,該方法也適用於個別物品。

Validate此方法會在自訂任務中被覆寫,無論是在 SSIS 設計器中驗證物件,或是程式碼呼叫時。 欲了解更多關於撰寫 Validate 自訂任務方法的資訊,請參閱 「自訂任務編碼」一文。

適用於