Lenguaje

Connections.Add(String) Método

Definición

Añade un ConnectionManager objeto del tipo de conexión especificado a la Connections colección.

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

Parámetros

connectionType
String

Este parámetro especifica el tipo de conexión. Por ejemplo, la cadena "FILE" especifica un gestor de conexiones para archivos.

Devoluciones

El nuevo ConnectionManager objeto que se añadió a la Connections colección.

Ejemplos

El siguiente ejemplo de código añade un gestor de conexiones ADO.NET a un paquete que contiene dos conexiones existentes.

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  

Salida de muestra:

The number of connections is: 2

The number of connections now is: 3

Comentarios

El valor utilizado para el connectionType parámetro en este método es el valor que se muestra en la propiedad ConnectionManagerType en el Diseñador. SQL Server (SSIS) incluye varios tipos de conexión comunes, entre ellos los siguientes tipos de gestor de conexión:

  • ADO para acceder a objetos Microsoft ActiveX Data Objects (ADO)

  • ADO.NET para acceder a objetos ADO.NET

  • FILE para acceder a archivos

  • FLATFILE para acceder a datos en archivos planos

  • HTTP para acceder a un servidor web

  • OLEDB para acceder a fuentes de datos relacionales usando OLE DB

  • ODBC para acceder a bases de datos usando ODBC

  • Instrumentación de Gestión de Windows (WMI) para acceder a un servidor y especificar el alcance de la gestión en el servidor

  • FTP para acceder a un servidor y enviar y recibir archivos

  • MSOLAP100 para acceder a una instancia de Microsoft SQL Server Analysis Services o a un proyecto de Analysis Services

Para más información sobre las cadenas de tipos de conexión válidas, consulte Conexiones de Servicios de Integración (SSIS).

Se aplica a