Linguaggio

Connections.Add(String) Metodo

Definizione

Aggiunge un ConnectionManager oggetto del tipo di connessione specificato alla Connections collezione.

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

Parametri

connectionType
String

Questo parametro specifica il tipo di connessione. Ad esempio, la stringa "FILE" specifica un gestore di connessione per i file.

Valori restituiti

Il nuovo ConnectionManager oggetto che era stato aggiunto alla Connections collezione.

Esempio

Il seguente esempio di codice aggiunge un gestore di connessione ADO.NET a un pacchetto che contiene due connessioni esistenti.

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  

Output di esempio:

The number of connections is: 2

The number of connections now is: 3

Commenti

Il valore utilizzato per il connectionType parametro in questo metodo è il valore mostrato nella proprietà ConnectionManagerType nel Designer. SQL Server (SSIS) include diversi tipi di connessione comuni, tra cui i seguenti tipi di gestore connessioni:

  • ADO per accedere agli oggetti Microsoft ActiveX Data Objects (ADO)

  • ADO.NET per accedere agli oggetti ADO.NET

  • FILE per accedere ai file

  • FLATFILE per accedere ai dati in file piatti

  • HTTP per accedere a un server Web

  • OLEDB per accedere a fonti dati relazionali utilizzando OLE DB

  • ODBC per accedere a database utilizzando ODBC

  • Windows Management Instrumentation (WMI) per accedere a un server e specificare l'ambito di gestione sul server

  • FTP per accedere a un server per inviare e ricevere file

  • MSOLAP100 per accedere a un'istanza di Microsoft SQL Server Analysis Services o a un progetto di Analysis Services

Per maggiori informazioni sulle stringhe valide dei tipi di connessione, vedi Connection Services (SSIS).

Si applica a