PipelineComponent.AcquireConnections メソッド
接続マネージャーへの接続を確立します。
名前空間: Microsoft.SqlServer.Dts.Pipeline
アセンブリ: Microsoft.SqlServer.PipelineHost (Microsoft.SqlServer.PipelineHost.dll)
構文
'宣言
Public Overridable Sub AcquireConnections ( _
transaction As Object _
)
'使用
Dim instance As PipelineComponent
Dim transaction As Object
instance.AcquireConnections(transaction)
public virtual void AcquireConnections(
Object transaction
)
public:
virtual void AcquireConnections(
Object^ transaction
)
abstract AcquireConnections :
transaction:Object -> unit
override AcquireConnections :
transaction:Object -> unit
public function AcquireConnections(
transaction : Object
)
パラメーター
- transaction
型: System.Object
接続が参加しているトランザクションです。
説明
AcquireConnections は、コンポーネントのデザイン時と実行時の両方で呼び出されます。 外部データ ソースに接続するコンポーネントは、このメソッドの間にこれらの接続を確立する必要があります。 このメソッドで確立されたすべての接続は、ローカル メンバー変数にキャッシュし、ReleaseConnections メソッドで解放する必要があります。 接続は、AcquireConnections のみで確立する必要があります。
使用例
次の例は、AcquireConnections の間に ADO.NET 接続マネージャーに接続するコンポーネントを示します。
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