PipelineComponent.AcquireConnections(Object) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Stabilisce una connessione a una gestione connessione.
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)
Parametri
- transaction
- Object
Transazione a cui partecipa la connessione.
Esempio
Nell'esempio seguente viene illustrato un componente che si connette a una gestione connessione ADO.NET durante 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
Commenti
AcquireConnections viene chiamato durante la progettazione e l'esecuzione dei componenti. I componenti che si connettono a origini dati esterne devono stabilire le connessioni durante questo metodo. Qualsiasi connessione stabilita durante questo metodo deve essere memorizzata nella cache in una variabile membro locale e rilasciata nel ReleaseConnections metodo . Le connessioni devono essere stabilite solo durante AcquireConnections.