Partilhar via


DtsConvert.ToConnectionManager Method

Converts a native connection manager to a managed ConnectionManager class. This method is not CLS-compliant.

Namespace: Microsoft.SqlServer.Dts.Runtime
Assembly: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)

Syntax

'Declaration
Public Shared Function ToConnectionManager ( _
    connMgr90 As IDTSConnectionManager90 _
) As ConnectionManager
public static ConnectionManager ToConnectionManager (
    IDTSConnectionManager90 connMgr90
)
public:
static ConnectionManager^ ToConnectionManager (
    IDTSConnectionManager90^ connMgr90
)
public static ConnectionManager ToConnectionManager (
    IDTSConnectionManager90 connMgr90
)
public static function ToConnectionManager (
    connMgr90 : IDTSConnectionManager90
) : ConnectionManager

Parameters

  • connMgr90
    The native connection manager

Return Value

The managed ConnectionManager class

Example

The following code example shows a pipeline component that connects to an ADO.NET connection manager during AcquireConnections, using the ToConnectionManager to convert the connection to a managed connection.

public override void AcquireConnections(object transaction)
{
    if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null)
    {
            // Convert the native IDTSConnectionManager90 to the managed ConnectionManager,
            // then retrieve the underlying connection through the InnerObject.
            ConnectionManager cm = Microsoft.SqlServer.Dts.Runtime.DtsConvert.ToConnectionManager(ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager);
            ConnectionManagerAdoNet cmado = cm.InnerObject  as ConnectionManagerAdoNet;

            // If the InnerObject is not an ConnectionManagerAdoNet, then
            // the cmado object is null.
            if( cmado == null )
                throw new Exception("The ConnectionManager " + cm.Name + " is not an ADO.NET connection.");

            // Get the underlying connection object.
            this.oledbConnection = cmado.AcquireConnection(transaction) as OleDbConnection;

            if( this.oledbConnection == null )
throw new Exception("The ConnectionManager " + cm.Name + " is not an ADO.NET connection.");

            isConnected = true;
        }
    }
}
Public Overrides  Sub AcquireConnections(ByVal transaction As Object)
    If Not ComponentMetaData.RuntimeConnectionCollection(0).ConnectionManager Is Nothing Then
            ' Convert the native IDTSConnectionManager90 to the managed ConnectionManager,
            ' then retrieve the underlying connection through the InnerObject.
            Dim cm As ConnectionManager =  Microsoft.SqlServer.Dts.Runtime.DtsConvert.ToConnectionManager(ComponentMetaData.RuntimeConnectionCollection(0).ConnectionManager) 
            Dim cmado As ConnectionManagerAdoNet =  cm.InnerObject as ConnectionManagerAdoNet 
 
            ' If the InnerObject is not an ConnectionManagerAdoNet, then
            ' the cmado object is null.
            If cmado Is Nothing Then
                Throw New Exception("The ConnectionManager " + cm.Name + " is not an ADO.NET connection.")
            End If
 
            ' Get the underlying connection object.
            Me.oledbConnection = cmado.AcquireConnectionCType(as OleDbConnection, transaction)
 
            If Me.oledbConnection Is Nothing Then
Throw New Exception("The ConnectionManager " + cm.Name + " is not an ADO.NET connection.")
            End If
 
            isConnected = True
    End If
End Sub
}

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

Target Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

See Also

Reference

DtsConvert Class
DtsConvert Members
Microsoft.SqlServer.Dts.Runtime Namespace