Thanks for your response. I have put together a very simple sample to reproduce my problem. It is a ConnectionManager and a CustomSource component that does nothing. When I debug I get the exact same behavior is my code. ConnectionManager establishes a connection fine at design time and the Runtime collection that holds the connection manager is null at run time. My code is below. It is this line if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null) that runs during AcquireConnection of my source component and the RuntimeConnectionCollection[0].ConnectionManager is always null. All my reading says the reason this happens is the developer has not set the connection during design time but that isn't the case. I can set the connection manager on my component, save and reopen visual studio and it saves fine. Then debug in design time and the connection establishes. Only during runtime does it not work. Please save me. :)
ConnectionManager Class
[DtsConnection(ConnectionType = "HTTPConnection",
DisplayName = "Http Connection Manager")]
public class HttpConnectionManager: ConnectionManagerBase
{
private HttpClient client;
[CategoryAttribute("Url")]
[Description("Url for HTTP Connection")]
public string ServerUrl { get; set; }
public override Microsoft.SqlServer.Dts.Runtime.DTSExecResult Validate(Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents infoEvents)
{
if (string.IsNullOrWhiteSpace(ServerUrl))
{
return DTSExecResult.Failure;
}
return DTSExecResult.Success;
}
public override object AcquireConnection(object txn)
{
var client = new HttpClient();
return client;
}
public override void ReleaseConnection(object connection)
{
if (client != null)
{
var client = connection as HttpClient;
client.Dispose();
client = null;
}
}
}
Source Component
[DtsPipelineComponent(DisplayName = "Custom Source",
ComponentType = ComponentType.SourceAdapter,
Description = "Custom Source Component Test")]
public class CustomSourceComponent: PipelineComponent
{
private HttpConnectionManager httpConnection;
private HttpClient client;
public override void ProvideComponentProperties()
{
// Reset the component.
base.RemoveAllInputsOutputsAndCustomProperties();
ComponentMetaData.RuntimeConnectionCollection.RemoveAll();
IDTSOutput100 output = ComponentMetaData.OutputCollection.New();
output.Name = "Output";
IDTSOutputColumn100 column1 = output.OutputColumnCollection.New();
IDTSExternalMetadataColumn100 exColumn1 = output.ExternalMetadataColumnCollection.New();
column1.Name = "HTML";
column1.SetDataTypeProperties(Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_WSTR, 4000, 0, 0, 0);
IDTSRuntimeConnection100 connection = ComponentMetaData.RuntimeConnectionCollection.New();
connection.Name = "Http Connection";
}
public override void AcquireConnections(object transaction)
{
if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null)
{
ConnectionManager connectionManager = Microsoft.SqlServer.Dts.Runtime.DtsConvert.GetWrapper(
ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager);
this.httpConnection = connectionManager.InnerObject as HttpConnectionManager;
if (this.httpConnection == null)
throw new Exception("Couldn't get the HttpConnectionManager instance");
client = this.httpConnection.AcquireConnection(transaction) as HttpClient;
}
}
public override void ReleaseConnections()
{
if (this.httpConnection != null)
{
this.httpConnection.ReleaseConnection(client);
client = null;
}
}
}