Aracılığıyla paylaş


DtsEventHandlers.Add Yöntemi

Yeni bir olay ekler DtsEventHandlers koleksiyon.

Ad Alanı:  Microsoft.SqlServer.Dts.Runtime
Derleme:  Microsoft.SqlServer.ManagedDTS (Microsoft.SqlServer.ManagedDTS içinde.dll)

Sözdizimi

'Bildirim
Public Function Add ( _
    eventName As String _
) As Object
'Kullanım
Dim instance As DtsEventHandlers
Dim eventName As String
Dim returnValue As Object

returnValue = instance.Add(eventName)
public Object Add(
    string eventName
)
public:
Object^ Add(
    String^ eventName
)
member Add : 
        eventName:string -> Object 
public function Add(
    eventName : String
) : Object

Parametreler

  • eventName
    Tür: System.String
    Koleksiyon eklemek için olay adı.

Dönüş Değeri

Tür: System.Object
DtsEventHandler İçin eklenen nesne koleksiyon.

Açıklamalar

Tümleştirme Hizmetleri yanında kendi özel olaylar oluşturma olanak sağlayarak birçok olay sağlar.Olay işleyicileri hakkında daha fazla bilgi için bkz: Tümleştirme Hizmetleri olay işleyicileri ve Olay işleyicilerini paketi ekleme.Özel olaylar hakkında daha fazla bilgi için bkz: Özel görev geliştirme.

Örnekler

Aşağıdaki kod örneği oluşturur bir DtsEventHandler için OnError olay paket.Bu DtsEventHandler kapsayıcı iki yürütülebilir dosyaları içerir ve bunlar arasında bir öncelik kısıtlaması kurar.Kod örneği, kapsayıcı içindeki Yürütülebilirler sayısı yanı sıra kapsayıcı öncelik kısıtlamaları sayısını görüntüler.Kod örneği bir yürütülebilir dosyayı kaldırır ve bu sayı re-displays.

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

namespace Microsoft.SqlServer.SSIS.Samples
{
    class Program
    {
        static void Main(string[] args)
        {
            Package pkg = new Package();
            // Set up a DtsEventHandler for the OnError event of the package.
            DtsEventHandler dtsEH = (DtsEventHandler)pkg.EventHandlers.Add("OnError");

            // Show the name and type of the properties in DtsEventHandler
            // using the Properties collection.
            DtsProperties props = dtsEH.Properties;
            String name;
            TypeCode propType;
            foreach (DtsProperty prop in props)
            {
                propType = prop.Type;
                name = prop.Name;
                Console.WriteLine("Name {0}, Type {1}", name, propType);
            }

            // When an OnError Event occurs, the Executables collection contains
            // the items to run. For this example, there will be a SendMailtTask
            // and a BulkInsertTask with a precedence constraint between them.
            Executable dtsEH1 = dtsEH.Executables.Add("STOCK:SendMailTask");
            TaskHost th = (TaskHost)dtsEH1;
            SendMailTask smTask = (SendMailTask)th.InnerObject;
            smTask.Subject = "Send Mail task";
            
            // Add a second executable to the DtsEventHandler.
            Executable dtsEH2 = dtsEH.Executables.Add("STOCK:BulkInsertTask");
            TaskHost th2 = (TaskHost)dtsEH2;

            // Add a precedence constraint between the two tasks.
            PrecedenceConstraint pc = dtsEH.PrecedenceConstraints.Add(dtsEH1, dtsEH2);
            pc.Value = DTSExecResult.Completion;

            // Review the number of constraints in the DtsEventHandler collection.
            PrecedenceConstraints pcDTSEH = dtsEH.PrecedenceConstraints;
            Console.WriteLine("Number of precedence constraints in DtsEventHandler: {0}", dtsEH.PrecedenceConstraints.Count);

            // Review the number of executables in the DtsEventHandler collection.
            Console.WriteLine("Number of executables in DtsEventHandler: {0}", dtsEH.Executables.Count);

            // Remove the first executable in the DtsEventHandler collection.
            dtsEH.Executables.Remove(0);
            Console.WriteLine("New number of exeutables in DtsEventHandler: {0}", dtsEH.Executables.Count);
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.SendMailTask
Imports Microsoft.SqlServer.Dts.Tasks.BulkInsertTask
 
Namespace Microsoft.SqlServer.SSIS.Samples
    Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim pkg As Package =  New Package() 
            ' Set up a DtsEventHandler for the OnError event of the package.
            Dim dtsEH As DtsEventHandler = CType(pkg.EventHandlers.Add("OnError"), DtsEventHandler)
 
            ' Show the name and type of the properties in DtsEventHandler
            ' using the Properties collection.
            Dim props As DtsProperties =  dtsEH.Properties 
            Dim name As String
            Dim propType As TypeCode
            Dim prop As DtsProperty
            For Each prop In props
                propType = prop.Type
                name = prop.Name
                Console.WriteLine("Name {0}, Type {1}", name, propType)
            Next
 
            ' When an OnError Event occurs, the Executables collection contains
            ' the items to run. For this example, there will be a SendMailtTask
            ' and a BulkInsertTask with a precedence constraint between them.
            Dim dtsEH1 As Executable =  dtsEH.Executables.Add("STOCK:SendMailTask") 
            Dim th As TaskHost = CType(dtsEH1, TaskHost)
            Dim smTask As SendMailTask = CType(th.InnerObject, SendMailTask)
            smTask.Subject = "Send Mail task"
 
            ' Add a second executable to the DtsEventHandler.
            Dim dtsEH2 As Executable =  dtsEH.Executables.Add("STOCK:BulkInsertTask") 
            Dim th2 As TaskHost = CType(dtsEH2, TaskHost)
 
            ' Add a precedence constraint between the two tasks.
            Dim pc As PrecedenceConstraint =  dtsEH.PrecedenceConstraints.Add(dtsEH1,dtsEH2) 
            pc.Value = DTSExecResult.Completion
 
            ' Review the number of constraints in the DtsEventHandler collection.
            Dim pcDTSEH As PrecedenceConstraints =  dtsEH.PrecedenceConstraints 
            Console.WriteLine("Number of precedence constraints in DtsEventHandler: {0}", dtsEH.PrecedenceConstraints.Count)
 
            ' Review the number of executables in the DtsEventHandler collection.
            Console.WriteLine("Number of executables in DtsEventHandler: {0}", dtsEH.Executables.Count)
 
            ' Remove the first executable in the DtsEventHandler collection.
            dtsEH.Executables.Remove(0)
            Console.WriteLine("New number of exeutables in DtsEventHandler: {0}", dtsEH.Executables.Count)
        End Sub
    End Class
End Namespace

Örnek Çıktı:

Adı CreationName, dize türünde

Adı DelayValidation, Boole türü

Dize türünde adı açıklama

Adı devre dışı bırakma, Boole türü

Yürütülebilir adı, nesne türü

Adı ExecutionDuration, türü Int32

ExecutionResult adı, nesne türü

ExecutionStatus adı, nesne türü

Değişkenleri adı, nesne türü

Öncelik kısıtlamaları içinde DtsEventHandler sayısı: 1

DtsEventHandler içindeki Yürütülebilirler sayısı: 2

Yeni DtsEventHandler de exeutables sayısı: 1