语言

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 用于访问平面文件中的数据

  • 用于访问Web服务器的HTTP

  • 用于使用 OLE DB 访问关系型数据源的 OLEDB

  • ODBC 用于使用 ODBC 访问数据库

  • Windows 管理仪器(WMI),用于访问服务器并指定服务器管理范围

  • FTP 用于访问服务器以发送和接收文件

  • MSOLAP100用于访问Microsoft SQL Server Analysis Services或分析服务项目的实例

有关有效连接类型字符串的更多信息,请参见 集成服务(SSIS)连接。

适用于