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

  • 用于访问文件的文件

  • FLATFILE 用于访问平面文件中的数据

  • 用于访问 Web 服务器的 HTTP

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

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

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

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

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

有关有效连接字符串的详细信息,请参阅 Integration Services (SSIS) Connections

适用于