Program aracılığıyla veri akışı bileşenleri ekleme
Veri akışı oluştururken bileşenleri ekleyerek başlayın. Sonra bu bileşenleri yapılandırmak ve birlikte çalışma zamanında veri akışını kurmak üzere bağlayın. Bu bölümde, veri akışı görev için bir bileşen ekleme, bileşen Tasarım Zamanı örneğini oluşturma ve bileşen yapılandırma anlatılmaktadır. 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
Arama Newyöntemi ComponentMetaDataCollectionyeni bir bileşen oluşturmak ve veri akışı görev eklemek için koleksiyon. Bu yöntem döndürür IDTSComponentMetaData100arabirimi bileşeninin. Ancak, bu noktada, IDTSComponentMetaData100herhangi bir bileşene özgü bilgiler içermez. Set ComponentClassIDbileşeni türünü belirlemek için özellik. Veri akışı görev, çalışma zamanında bileşeni örneği oluşturmak için bu özelliğin değeri kullanır.
Belirtilen değeri ComponentClassIDözelliği CLSID, ProgID, olabilir veya CreationNameözelliği bileşeninin. CLSID normalde bileşenin değeri gibi Özellikler penceresinde görüntülenir ComponentClassIDözellik. Bu özellik ve diğer özellikleri kullanılabilir bileşenleri hakkında daha fazla bilgi için bkz: Program aracılığıyla veri akışı bileşenleri keşfetme.
Yönetilen bir bileşen ekleme
Bu değerler bir wrapper ve bileşenin kendisi işaret bir veri akışı, yönetilen veri akışı bileşenleri eklemek için ProgID veya CLSID kullanamazsınız. Onun yerine sen-ebilmek kullanma CreationNameözelliği ya da AssemblyQualifiedNameAşağıdaki örnekte gösterildiği gibi özellik.
Kullanmayı düşünüyorsanız AssemblyQualifiedNameözelliği, daha sonra başvuru eklemeniz gerekir, Visual StudioYönetilen bileşen içeren derleme proje. Aşağıdaki derlemeler listelenen değil.net sekmesi Add Reference iletişim kutusu. Normalde derleme bulmak için gözatmanız gerekir C:\Program Files\Microsoft SQL Server\100\DTS\PipelineComponentsklasör.
Yerleşik yönetilen veri akışı bileşenlerini içerir:
ADO.NETKaynak
xml kaynağı
DataReader hedef
SQL ServerCompact hedef
Script bileşeni
Her iki yönde veri akışı yönetilen bir bileşen ekleme aşağıdaki kod örneği göstermektedir:
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;
}
}
}
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
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
Bileşen Tasarım Zamanı örneğini oluşturma
Arama Instantiateyöntemi ile tanımlanan bileşen Tasarım Zamanı örneğini oluşturmak için ComponentClassIDözellik. Bu yöntem döndürür CManagedComponentWrapperolan Yönetilen sarıcı nesnesi için IDTSDesigntimeComponent100arabirimi.
Mümkün olduğunca bileşen meta verileri doğrudan değiştirerek yerine tasarım zamanı örnek yöntemleri kullanarak bir bileşenin değiştirmelisiniz. Genellikle olmasına rağmen öğeleri doğrudan bağlantılar gibi ayarlamanız gereken meta veri meta verileri doğrudan değiştiremezsiniz, çünkü yeteneği izlemek ve değişiklikleri doğrulamak için bileşenin atlamak için yıkıcıda.
Bağlantılara atama
ole db kaynağı bileşeni gibi bazı bileşenlerini dış veri bağlantısı gerektirir ve mevcut ConnectionManagerBu amaçla paket nesnesinde. CountÖzelliği RuntimeConnectionCollectionkoleksiyonu çalıştırma gösterir ConnectionManagerbileşeni tarafından gereken nesneleri. Sayı sıfırdan büyükse, bileşen bağlantısı gerekir. Paketinden Bağlantı Yöneticisi bileşeni belirterek ATA ConnectionManagerve Nameilk bağlantı özelliklerini RuntimeConnectionCollection. Çalışma Zamanı bağlantı toplama Bağlantı Yöneticisi adı Bağlantı Yöneticisi adı eşleşmelidir Notpaketinden başvurulan.
Özel özelliklerin değerlerini ayarlama
Bileşen Tasarım Zamanı örneği oluşturduktan sonra çağrı ProvideComponentPropertiesyöntemi. Bu yöntem için yapıcı benzer çünkü o özel özelliklerini ve giriş ve çıkış nesneleri oluşturarak yeni oluşturulan bileşen başlatır. Arama yapmak ProvideComponentPropertieszaman birden fazla bir bileşen, bileşenin kendisini sıfırlamak ve meta verileri için daha önce yapılan değişiklikleri kaybedersiniz.
CustomPropertyCollectionBir bileşeni içerir IDTSCustomProperty100bileşene özgü nesneleri. Görüşme sırasında nerede bir nesnenin özelliklerini her zaman nesne üzerinde görünür, diğer programlama modelleri bileşenleri yalnızca kendi özel özellik koleksiyonu doldurmak ProvideComponentPropertiesyöntemi. Kullanma yöntemini çağırdıktan sonra SetComponentPropertyyöntemi özel özelliklerini değerleri atamak için bileşen tasarım zamanı örneği. Bu yöntem, özel özellik tanımlar ve yeni değeri sağlayan 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 sütunlar koleksiyonu başlatmak IDTSOutput100nesnenin. Bu adım için kaynak bileşenleri özellikle ilgili olmakla birlikte, çünkü bunlar genellikle ters yönde bileşenlerinden aldıkları sütunları temel alan sütunlar için dönüşüm ve hedef bileşenleri başlatmak değil.
Arama ReinitializeMetaDatayöntemi kaynak bileşen çıkış sütunları başlatılamıyor. Bileşenleri otomatik olarak dış veri kaynaklarına bağlanmak yok çünkü AcquireConnectionsönce arama yöntemi ReinitializeMetaDatadış veri kaynağını ve yeteneği sütun meta verileri doldurmak için Bileşen erişimi sağlamak için. Sonunda, ReleaseConnectionsyöntem bağlantıyı bırakın.
Sonraki Adım
Ekleme ve bileşen yapılandırdıktan sonra tartışılan konu, bileşenler arasındaki yolu oluşturmak için sonraki adıma olur bir yolu arasında iki bileşeni oluşturma.
Örnek
Aşağıdaki kod örneği ole db kaynağı bileşeni için veri akışı görev ekler, bileşen Tasarım Zamanı bir örneğini oluşturur ve bileşenin özelliklerini yapılandırır. Bu örnek derleme Microsoft.SqlServer.DTSRuntimeWrap ek bir başvuru gerektirir.
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=AdventureWorks;Provider=SQLOLEDB.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.1";
// 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.
}
}
}
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=AdventureWorks;Provider=SQLOLEDB.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.1";
// 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=AdventureWorks;Provider=SQLOLEDB.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.1"
' 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
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=AdventureWorks;Provider=SQLOLEDB.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.1"
' 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
Dış Kaynaklar
Blog girişi, EzAPI – alternatif paket oluşturma API'si, blogs.MSDN.com üzerinde.
|