Connections.Add(String) Méthode

Définition

Ajoute un objet ConnectionManager du type de connexion spécifié à la collection 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

Paramètres

connectionType
String

Ce paramètre spécifie le type de connexion. Par exemple, la chaîne « FILE » spécifie un gestionnaire de connexions pour les fichiers.

Retours

Nouvel objet ConnectionManager ajouté à la collection Connections.

Exemples

L’exemple de code suivant ajoute un gestionnaire de connexions ADO.NET à un package qui contient deux connexions existantes.

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  

Exemple de sortie :

The number of connections is: 2

The number of connections now is: 3

Remarques

La valeur utilisée pour le connectionType paramètre de cette méthode est la valeur affichée dans la propriété ConnectionManagerType dans le Concepteur. SQL Server (SSIS) comprend plusieurs types de connexions courants, notamment les types de gestionnaire de connexions suivants :

  • ADO pour accéder aux objets Ado (Microsoft ActiveX Data Objects)

  • ADO.NET pour accéder aux objets ADO.NET

  • FICHIER pour accéder aux fichiers

  • FLATFILE pour accéder aux données dans des fichiers plats

  • HTTP pour accéder à un serveur web

  • OLEDB pour accéder aux sources de données relationnelles à l’aide d’OLE DB

  • ODBC pour accéder aux bases de données à l’aide d’ODBC

  • Windows Management Instrumentation (WMI) pour accéder à un serveur et spécifier l’étendue de la gestion sur le serveur

  • FTP pour accéder à un serveur pour envoyer et recevoir des fichiers

  • MSOLAP100 pour accéder à une instance de Microsoft SQL Server Analysis Services ou à un projet Analysis Services

Pour plus d’informations sur les chaînes de type de connexion valides, consultez Connexions Integration Services (SSIS).

S’applique à