Share via


Connections 屬性

Returns the Connections collection of existing connections defined in the package that contains the Script task.

命名空間:  Microsoft.SqlServer.Dts.Tasks.ScriptTask
組件:  Microsoft.SqlServer.ScriptTask (在 Microsoft.SqlServer.ScriptTask.dll 中)

語法

'宣告
Public ReadOnly Property Connections As Connections
    Get
'用途
Dim instance As ScriptObjectModel
Dim value As Connections

value = instance.Connections
public Connections Connections { get; }
public:
property Connections^ Connections {
    Connections^ get ();
}
member Connections : Connections
function get Connections () : Connections

屬性值

型別:Microsoft.SqlServer.Dts.Runtime. . :: . .Connections
The Connections collection of existing connections defined in the package that contains the Script task.

備註

Use the Connections property of the Dts object in Script task code to access connection managers defined in the package.

範例

The following sample of code for use inside a Script task demonstrates how to access connection managers from within the Script task. The sample assumes that you have created and configured an ADO.NET connection manager named Test ADO.NET Connection and a Flat File connection manager named Test Flat File Connection. Note that the ADO.NET connection manager returns a SqlConnection object that you can use immediately to connect to the data source. The Flat File connection manager, on the other hand, returns only a string that contains the path and filename. You must use methods from the System.IO namespace to open and work with the flat file.

Public Sub Main()

    Dim myADONETConnection As SqlClient.SqlConnection
    myADONETConnection = _
        DirectCast(Dts.Connections("Test ADO.NET Connection").AcquireConnection(Dts.Transaction), _
        SqlClient.SqlConnection)
    MsgBox(myADONETConnection.ConnectionString, _
        MsgBoxStyle.Information, "ADO.NET Connection")

    Dim myFlatFileConnection As String
    myFlatFileConnection = _
        DirectCast(Dts.Connections("Test Flat File Connection").AcquireConnection(Dts.Transaction), _
        String)
    MsgBox(myFlatFileConnection, MsgBoxStyle.Information, "Flat File Connection")

    Dts.TaskResult = ScriptResults.Success

End Sub