語言

Connections.Add(String) 方法

定義

將ConnectionManager指定連線類型的物件加入集合。Connections

public:
 Microsoft::SqlServer::Dts::Runtime::ConnectionManager ^ Add(System::String ^ connectionType);
public Microsoft.SqlServer.Dts.Runtime.ConnectionManager Add(string connectionType);
member this.Add : string -> Microsoft.SqlServer.Dts.Runtime.ConnectionManager
Public Function Add (connectionType As String) As ConnectionManager

參數

connectionType
String

此參數指定連接類型。 例如,字串「FILE」指定檔案的連線管理器。

傳回

新 ConnectionManager 加入 Connections 收藏的物品。

範例

以下程式碼範例將 ADO.NET 連線管理器加入包含兩個現有連線的套件。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace ConnMgr_GetEnum_Current  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // The package is one of the SSIS Samples.  
            string mySample = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";  
            // Create an application and load the sample.  
            Application app = new Application();  
            Package pkg = app.LoadPackage(mySample, null);  

            // Get the Connections collection from the package.  
            Connections conns = pkg.Connections;  

            // Count the number of connections in the package.  
            int myConns = conns.Count;  
            Console.WriteLine("The number of connections is: {0}", myConns);  

            //Add a new connection manager to the collection.  
            conns.Add("ADO.NET");  
            myConns = conns.Count;  
            Console.WriteLine("The number of connections now is: {0}", myConns);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace ConnMgr_GetEnum_Current  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            ' The package is one of the SSIS Samples.  
            Dim mySample As String =  "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"   
            ' Create an application and load the sample.  
            Dim app As Application =  New Application()   
            Dim pkg As Package =  app.LoadPackage(mySample,Nothing)   

            ' Get the Connections collection from the package.  
            Dim conns As Connections =  pkg.Connections   

            ' Count the number of connections in the package.  
            Dim myConns As Integer =  conns.Count   
            Console.WriteLine("The number of connections is: {0}", myConns)  

            'Add a new connection manager to the collection.  
            conns.Add("ADO.NET")  
            myConns = conns.Count  
            Console.WriteLine("The number of connections now is: {0}", myConns)  
        End Sub  
    End Class  
End Namespace  

範例輸出:

The number of connections is: 2

The number of connections now is: 3

備註

此方法中參數的 connectionType 值即為設計器中 ConnectionManagerType 屬性中所示的值。 SQL Server(SSIS)包含幾種常見的連線類型,包括以下連線管理器類型:

  • 存取 Microsoft ActiveX Data Objects (ADO) 物件的 ADO

  • ADO.NET 用於存取 ADO.NET 物件

  • 用於存取檔案的 FILE

  • FLATFILE 用於存取平面檔案中的資料

  • HTTP 用於存取網頁伺服器

  • 使用 OLE DB 存取關聯式資料來源的 OLEDB

  • 使用 ODBC 存取資料庫

  • Windows 管理儀器(WMI)用於存取伺服器並指定伺服器管理範圍

  • FTP 用於存取伺服器以傳送和接收檔案

  • MSOLAP100 用於存取 Microsoft SQL Server Analysis Services 或 Analysis Services 專案的實例

欲了解更多關於有效連線類型字串的資訊,請參閱 整合服務(SSIS)連線。

適用於