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 自定义任务的方法的详细信息,请参阅 编写自定义任务的代码

适用于