Friday, March 30, 2012

Having trouble getting connections

I have a custom Data Flow Destination Adapter that is looking for a particular type of ConnectionManager. I want to check that this connection exists in the Validate method. I first checked the ComponentMetedata.RuntimeConnections, but it was was an empty collection. I am guessing that it gets populated at runtime. Is there anything available for to check at design time?

Another way of asking this would be, Is there a way to programatically select which ConnectionManager gets assigned to a RuntimeConnection? Normally, this is done on the Connections tab of the Advanced Editor.

Thanks,

Graham

You can assign a connection manager at design time to your adapter and check that it is the correct type in the Validate() method. You will need to let your component know that it is expecting a connection manager.


Allan

|||I realize that I can do that by opening the advanced editor on my destination task and selecting the connection; but I dont want to do it that way. I want to Programmatically look for a connection of a specific type. Below is a code snippet of what I tried to do, but that doesnt seem to work. The connection is not set.



//this takes place in the onload handler for my DestinationAdapter form
//connections is passed in from the UI class that implements IDtsComponentUI
ConnectionManager connMan = null;
foreach (ConnectionManager cm in connections)
{
if (cm.InnerObject.GetType() == typeof(ProfileConnectionManager))
{
connMan = cm;
}
}
profConnMan = ProfileConnectionManager.FindProfileConnection(connections);
dtsComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.ToConnectionManager90(connMan);


|||Is there a reason you don't just get the value of ConnectionManagerType on the properties collection? Also, you're attempting to use a managed code idiom for a connection that may not be managed. Most of the connection managers are native. Is this a custom connection manager? I don't know about the ProfileConnectionManager.|||

You may also want to take a look at IDtsConnectionService.GetConnections and IDtsConnectionService.CreateConnection. Useful for writing UIs. They all work around the connection type that Kirk mentions.

|||ProfileConnectionManager is a custom connection that I have written. I want to allow a custom data flow destination adapter that I have written to look for a ProfileConnectionManager and if one is defined, add it to my CustomDestinationAdapter.ComponentMetaData.RuntimeConnections collection.

In normal situations, this is done at design time by openning the advanced editor and selecting the connection manager from a dropdown. In my situation, I am allowing only one ProfileConnectionManger to be created. So if it exists, I dont want the user to have to select it from the advanced editor; I want that to be done programmatically by me.

When you refer to properties collection, are you saying I should add a property to MyCustomDestinationAdapter.ComponentMetaData.CustomPropertyCollection and assign my custom connection as its value?

thanks,
Graham|||

I would use GetConnections, albeit in a UI, something like this-

foreach (ConnectionManager connectionManager in _dtsConnectionService.GetConnectionsOfType(connectionType))
{
comboBox.Items.Add(connectionManager.Name);
}

connectionType is the string that identifies the type of connection I want. For example if I want ADO.Net SQLClient connections I need to use-

"ADO.NET:System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";

It is a bit annoying that I have to use the fully qualified name, but that's what works.

The ConnectionManager also has a CreationName property which I use often for validation, and Kirk suggests a ConnectionType property, so using this you could loop as you where above, and check such a property to see if it is your connection. What you should not do is try and get a .Net Type object for the connection manager, as not all of them are .Net objects.

sql

No comments:

Post a Comment