PipelineComponent.AcquireConnections(Object) 方法

定义

建立与连接管理器的连接。

public:
 virtual void AcquireConnections(System::Object ^ transaction);
public virtual void AcquireConnections (object transaction);
abstract member AcquireConnections : obj -> unit
override this.AcquireConnections : obj -> unit
Public Overridable Sub AcquireConnections (transaction As Object)

参数

transaction
Object

连接参与的事务。

示例

以下示例演示在 期间连接到 ADO.NET 连接管理器的 AcquireConnections组件。

public override void AcquireConnections(object transaction)  
{  
    if (ComponentMetaData.RuntimeConnectionCollection[0].ConnectionManager != null)  
    {  
            // Convert the native IDTSConnectionManager100 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 IDTSConnectionManager100 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 = CType(ConversionHelpers.AsWorkaround(cm.InnerObject, GetType(ConnectionManagerAdoNet)), 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 = CType(ConversionHelpers.AsWorkaround(cmado.AcquireConnection(transaction), GetType(OleDbConnection)), OleDbConnection)   
   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  

注解

AcquireConnections 在组件设计和执行期间调用 。 连接到外部数据源的组件应在此方法期间建立其连接。 在此方法期间建立的任何连接都应缓存在本地成员变量中,并在 方法中 ReleaseConnections 释放。 应仅在 期间 AcquireConnections建立连接。

适用于