Tuesday, March 27, 2012

Can't change the name of a OLE DB Source component name

Hi,

I've created an application that create package with a dataflow. The package with the dataflow and the ole db Source was created succesfully but for some reason the name of the Ole DB Source dosen't change programmitcally It's stays with the default name "OLE DB Source". This is very problematic because I want to add another Ole Db source and the package won't load because there will be two components with the same name.

Thanks.

This is the Code, It's from msdn exmples:

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("DTS.Pipeline.1")
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 IDTSComponentMetaData90 = _
dataFlowTask.ComponentMetaDataCollection.New()
component.Name = "AdventureWorks;Product"
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.ToConnectionManager90(package.Connections(0))
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

If I remember correctly, the Name should be set after the call to

instance.ProvideComponentProperties();

|||Thanks It works

No comments:

Post a Comment