Program aracılığıyla veri akışı bileşenleri ekleme

Veri akışı oluştururken bileşenleri ekleyerek başlayın.Bu bileşenleri yapılandırmak ve birlikte çalışma veri akışını oluşturmak için bunları bağlamak daha sonra saat.Bu bölüm oluşturma tasarım - veri akışı görevi için bir bileşen ekleme açıklarsaat bileşeni ve sonra bileşen yapılandırma örnek.Bileşenleri bağlama hakkında daha fazla bilgi için bkz: Program aracılığıyla veri akışı bileşenleri bağlama.

Bir bileşen ekleme

Call New yöntem, ComponentMetaDataCollection koleksiyon yeni bir bileşen oluşturmak ve veri akışı görevi. eklemek içinBu yöntem döndürür IDTSComponentMetaData100 arabirim bileşeni.Ancak, bu noktada, IDTSComponentMetaData100 özgü bilgileri içerirtek bir bileşen herhangi. Set ComponentClassID özellik tanımlamak tür bileşeni.Çalışma zamanında bileşenin bir örneğini oluşturmak için bu özelliğin değeri veri akışı görevi kullanır saat.

Belirtilen değer ComponentClassID özellik olabilir, ProgID CLSID veya CreationName özellik bileşen.CLSID normalde Properties penceresinde bileşenin değeri olarak görüntülenen ComponentClassID özellik.Bu özellik ve diğer özellikleri kullanılabilir bileşenler hakkında daha fazla bilgi için bkz: Program aracılığıyla veri akışı bileşenleri keşfetme.

Yönetilen bir bileşen ekleme

Çünkü bu değerler sarıcı ve bileşen işaret, ProgID ve CLSID bir veri akışı için yönetilen veri akışı bileşenleri eklemek için kullanamazsınız.Bunun yerine kullanabileceğiniz CreationName özellik veya AssemblyQualifiedName özellik olarak gösterilen aşağıdaki örnek.

Kullanmayı düşünüyorsanız, AssemblyQualifiedName özellik, sonra başvuru eklemeniz gerekir, Visual Studio Proje için derleme içeren yönetilen bir bileşen.Bu birleştirmeler listelenen değil.net sekmesi, Add Reference iletişim kutusu.Normal olarak, bulmak için Gözat gerekir derleme , C:\Program files\microsoft sql server\100\dts\pipelinecomponents klasörü.

Yerleşik yönetilen veri akışı bileşenleri içerir:

  • ADO.NET Source

  • xml kaynağı

  • DataReader hedef

  • SQL Server Compact hedef

  • Komut dosyası bileşeni

Her iki yönde veri akışı yönetilen bir bileşen ekleme aşağıdaki kod örneği gösterilmektedir:

using System;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Pipeline;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace Microsoft.SqlServer.Dts.Samples
{
  class Program
  {
    static void Main(string[] args)
    {
      Microsoft.SqlServer.Dts.Runtime.Package package = new Microsoft.SqlServer.Dts.Runtime.Package();
      Executable e = package.Executables.Add("STOCK:PipelineTask");
      Microsoft.SqlServer.Dts.Runtime.TaskHost thMainPipe = (Microsoft.SqlServer.Dts.Runtime.TaskHost)e;
      MainPipe dataFlowTask = (MainPipe)thMainPipe.InnerObject;

      // The Application object will be used to obtain the CreationName
      //  of a PipelineComponentInfo from its PipelineComponentInfos collection.
      Application app = new Application();

      // Add a first ADO NET source to the data flow.
      //  The CreationName property requires an Application instance.
      IDTSComponentMetaData100 component1 = dataFlowTask.ComponentMetaDataCollection.New();
      component1.Name = "DataReader Source";
      component1.ComponentClassID = app.PipelineComponentInfos["DataReader Source"].CreationName;

      // Add a second ADO NET source to the data flow.
      //  The AssemblyQualifiedName property requires a reference to the assembly.
      IDTSComponentMetaData100 component2 = dataFlowTask.ComponentMetaDataCollection.New();
      component2.Name = "DataReader Source";
      component2.ComponentClassID = typeof(Microsoft.SqlServer.Dts.Pipeline.DataReaderSourceAdapter).AssemblyQualifiedName;
    }
  }
}
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Module Module1

  Sub Main()

    Dim package As Microsoft.SqlServer.Dts.Runtime.Package = _
      New Microsoft.SqlServer.Dts.Runtime.Package()
    Dim e As Executable = package.Executables.Add("STOCK:PipelineTask")
    Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _
      CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)
    Dim dataFlowTask As MainPipe = CType(thMainPipe.InnerObject, MainPipe)

    ' The Application object will be used to obtain the CreationName
    '  of a PipelineComponentInfo from its PipelineComponentInfos collection.
    Dim app As New Application()

    ' Add a first ADO NET source to the data flow.
    '  The CreationName property requires an Application instance.
    Dim component1 As IDTSComponentMetaData100 = _
      dataFlowTask.ComponentMetaDataCollection.New()
    component1.Name = "DataReader Source"
    component1.ComponentClassID = app.PipelineComponentInfos("DataReader Source").CreationName

    ' Add a second ADO NET source to the data flow.
    '  The AssemblyQualifiedName property requires a reference to the assembly.
    Dim component2 As IDTSComponentMetaData100 = _
      dataFlowTask.ComponentMetaDataCollection.New()
    component2.Name = "DataReader Source"
    component2.ComponentClassID = _
      GetType(Microsoft.SqlServer.Dts.Pipeline.DataReaderSourceAdapter).AssemblyQualifiedName

  End Sub

End Module

Oluşturma tasarım -saat bileşen örneği

Call Instantiate tasarımı oluşturma yöntemi saat ile tanımlanan bileşen örneği ComponentClassID özellik.Bu yöntem döndürür CManagedComponentWrapper yönetilen sarıcı olan nesne için IDTSDesigntimeComponent100 arabirim.

Mümkün olduğunda, tasarım - yöntemlerini kullanarak bir bileşenin değiştirmelisinizsaat örnek yerine doğrudan bileşen meta veriler değiştirerek.Gereken meta veri öğeleri olmasına rağmen küme , doğrudan bağlantılar gibi genellikle bu yeteneği izlemek ve değişiklikleri doğrulamak için bileşenin atlamak için meta veriler doğrudan değiştirmek için önerilmez.

Bağlantıları atama

ole db kaynağı bileşeni gibi bazı bileşenlerini dış veri bağlantısı gerektirir ve varolan bir ConnectionManager nesne paket için bu amaç.The Count property of the RuntimeConnectionCollection collection indicates the number of run-time ConnectionManager objects required by the component.Sayı sıfırdan büyükse, bileşen bir bağlantı gerektirir.Belirterek paket bileşeni için bir Bağlantı Yöneticisi ata ConnectionManager ve Name ilk bağlantısında özelliklerinin RuntimeConnectionCollection.Note that the name of the connection manager in the run-time connection collection must match the name of the connection managerreferenced from the package.

Özel özelliklerin değerlerini ayarlama

Oluşturma tasarım - sonrasaat çağrısı bileşeni örnek ProvideComponentProperties yöntem.Bu yöntem için bir kurucu benzer çünkü özel özelliklerini ve giriş ve çıkış nesneleri oluşturarak yeni oluşturulan bileşen başlatır.Call ProvideComponentProperties daha fazla saat bir bileşende, bileşenin kendisini sıfırlaması ve onun metadata. için daha önce yapılan değişiklikleri kaybedersiniz çünkü

The CustomPropertyCollection of the component contains a collection of IDTSCustomProperty100 objects specific to the component.Aradığınızda, burada bir nesnenin özelliklerini her zaman nesne üzerinde görünür, diğer programlama modellerinin bileşenleri yalnızca kendi özel özellik koleksiyonu doldurmak ProvideComponentProperties yöntem.Kullanma yöntemni çağırdıktan sonra SetComponentProperty yöntem, tasarım -saat kendi özel özelliklerini. için değerleri atamak için bileşen örnekBu yöntem, özel özellik tanımlar ve yeni değeri sağlayan bir ad/değer çifti kabul eder.

Çıktı sütunları başlatılıyor

Görev için bir bileşen eklemek ve yapılandırmak sonra başlatmak koleksiyon sütun IDTSOutput100 nesne.Bu adımı kaynak bileşenleri için özellikle uygundur, ancak, çünkü bunlar genellikle ters yönde bileşenlerini aldıkları sütun bağımlı sütun dönüştürme ve hedef bileşenleri için başlatmak.

Call ReinitializeMetaData yöntem başlatmak sütunlarda çıkışlarına bir kaynak bileşeni.Bileşenleri otomatik olarak dış veri kaynağına bağlanmak değil çünkü kaynaks, çağrı AcquireConnections önce arama yöntem ReinitializeMetaData Bileşen erişebilmesi için dış veri kaynak ve onun sütun meta verilerleri. doldurmak içinSon olarak, çağrı ReleaseConnections yöntem bağlantı serbest bırakmak.

Sonraki Adım

Ekleme ve bileşen yapılandırdıktan sonra sonraki adım konusunda ele alınan, bileşenler arasındaki yolu oluşturmaktır bir yolu arasında iki bileşeni oluşturma.

Örnek

Aşağıdaki kod örnek ole db kaynağı bileşeni için veri akışı görevi ekler, tasarım - oluşturursaat bileşen örnek ve bileşenin özelliklerini yapılandırır.Bu örnek için ek bir başvuru gerektirir derleme Microsoft.SqlServer.DTSRuntimeWrap.

using System;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts.Pipeline;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace Microsoft.SqlServer.Dts.Samples
{
  class Program
  {
    static void Main(string[] args)
    {
      Runtime.Package package = new Runtime.Package();
      Executable e = package.Executables.Add("STOCK:PipelineTask");
      Runtime.TaskHost thMainPipe = e as Runtime.TaskHost;
      MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;
      
      // Add an OLEDB connection manager to the package.
      ConnectionManager cm = package.Connections.Add("OLEDB");
      cm.Name = "OLEDB ConnectionManager";
      cm.ConnectionString = "Data Source=(local);" + 
        "Initial Catalog=AdventureWorks2008R2;Provider=SQLNCLI11.1;" + 
        "Integrated Security=SSPI;"
      
      // Add an OLE DB source to the data flow.
      IDTSComponentMetaData100 component = 
        dataFlowTask.ComponentMetaDataCollection.New();
      component.Name = "OLEDBSource";
      component.ComponentClassID = "DTSAdapter.OleDbSource.2";
      // You can also use the CLSID of the component instead of the PROGID.
      //component.ComponentClassID = "{2C0A8BE5-1EDC-4353-A0EF-B778599C65A0}";

      // Get the design time instance of the component.
      CManagedComponentWrapper instance = component.Instantiate();

      // Initialize the component
      instance.ProvideComponentProperties();

      // Specify the connection manager.
      if (component.RuntimeConnectionCollection.Count > 0)
      {
        component.RuntimeConnectionCollection[0].ConnectionManager = 
          DtsConvert.GetExtendedInterface(package.Connections[0]);
        component.RuntimeConnectionCollection[0].ConnectionManagerID = 
          package.Connections[0].ID;      }

      // Set the custom properties.
      instance.SetComponentProperty("AccessMode", 2);
      instance.SetComponentProperty("SqlCommand", 
        "Select * from Production.Product");

      // Reinitialize the metadata.
      instance.AcquireConnections(null);
      instance.ReinitializeMetaData();
      instance.ReleaseConnections();

      // Add other components to the data flow and connect them.
    }
  }
}
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports Microsoft.SqlServer.Dts.Pipeline
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Module Module1

  Sub Main()

    Dim package As Microsoft.SqlServer.Dts.Runtime.Package = _
      New Microsoft.SqlServer.Dts.Runtime.Package()
    Dim e As Executable = package.Executables.Add("STOCK:PipelineTask")
    Dim thMainPipe As Microsoft.SqlServer.Dts.Runtime.TaskHost = _
      CType(e, Microsoft.SqlServer.Dts.Runtime.TaskHost)
    Dim dataFlowTask As MainPipe = CType(thMainPipe.InnerObject, MainPipe)

    ' Add an OLEDB connection manager to the package.
    Dim cm As ConnectionManager = package.Connections.Add("OLEDB")
    cm.Name = "OLEDB ConnectionManager"
    cm.ConnectionString = "Data Source=(local);" & _
      "Initial Catalog=AdventureWorks2008R2;Provider=SQLCLI11.1;" & _
      "Integrated Security=SSPI;"

    ' Add an OLE DB source to the data flow.
    Dim component As IDTSComponentMetaData100 = _
      dataFlowTask.ComponentMetaDataCollection.New()
    component.Name = "OLEDBSource"
    component.ComponentClassID = "DTSAdapter.OleDbSource.2"
    ' You can also use the CLSID of the component instead of the PROGID.
    'component.ComponentClassID = "{2C0A8BE5-1EDC-4353-A0EF-B778599C65A0}";

    ' Get the design time instance of the component.
    Dim instance As CManagedComponentWrapper = component.Instantiate()

    ' Initialize the component.
    instance.ProvideComponentProperties()

    ' Specify the connection manager.
    If component.RuntimeConnectionCollection.Count > 0 Then
      component.RuntimeConnectionCollection(0).ConnectionManager = _
        DtsConvert.GetExtendedInterface(package.Connections(0))
      component.RuntimeConnectionCollection(0).ConnectionManagerID = _
        package.Connections(0).ID
    End If

    ' Set the custom properties.
    instance.SetComponentProperty("AccessMode", 2)
    instance.SetComponentProperty("SqlCommand", _
      "Select * from Production.Product")

    ' Reinitialize the metadata.
    instance.AcquireConnections(vbNull)
    instance.ReinitializeMetaData()
    instance.ReleaseConnections()

    ' Add other components to the data flow and connect them.

  End Sub

End Module
Integration Services simgesi (küçük)Integration Services ile güncel kalın

En son karşıdan yüklemeleri, makaleler, örnekler ve videolarını Microsoftyanı olarak seçilen topluluk çözümleri ziyaret Integration Services sayfa msdn veya TechNet:

Bu güncelleştirmelerle ilgili otomatik bildirim almak için, sayfadaki RSS akışlarına abone olun.

Değişiklik Geçmişi

Güncelleştirilmiş içerik

SQLNCLI11.1 sağlayıcı ve DTSAdapter.OleDbSource.2 değeri için başvurmak için veri akışı görevi için ole db kaynağı bileşeni eklemek için örnek güncelleştirilmiş ComponentClassID.