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) включает несколько распространенных типов подключений, включая следующие типы диспетчера соединений:

  • ADO для доступа к объектам данных Microsoft ActiveX (ADO)

  • ADO.NET для доступа к объектам ADO.NET

  • FILE для доступа к файлам

  • FLATFILE для доступа к данным в неструктурированных файлах

  • HTTP для доступа к веб-серверу

  • OLEDB для доступа к реляционным источникам данных с помощью OLE DB

  • ODBC для доступа к базам данных с помощью ODBC

  • Инструментарий управления Windows (WMI) для доступа к серверу и указания области управления на сервере

  • FTP для доступа к серверу для отправки и получения файлов

  • MSOLAP100 для доступа к экземпляру Microsoft SQL Server Analysis Services или проекту служб Analysis Services

Дополнительные сведения о допустимых строках типа подключения см. в разделе "Подключения служб Integration Services (SSIS).

Применяется к