Package.Connections 属性

定义

获取包的连接管理器集合。

public:
 property Microsoft::SqlServer::Dts::Runtime::Connections ^ Connections { Microsoft::SqlServer::Dts::Runtime::Connections ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.Connections Connections { get; }
member this.Connections : Microsoft.SqlServer.Dts.Runtime.Connections
Public ReadOnly Property Connections As Connections

属性值

Connections

包的连接管理器集合。

示例

以下示例加载 UsingExecuteProcess 包示例,然后检索包使用的连接,并显示有关连接的一些属性。

static void Main(string[] args)  
        {  
            // The variable pkg points to the location  
            // of the ExecuteProcess package sample   
            // that is installed with the samples.  
            string pkg = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";  

            Application app = new Application();  
            Package p = app.LoadPackage(pkg, null);  
            Connections conns = p.Connections;  
            foreach (ConnectionManager cm in conns)  
                Console.WriteLine("Name = " + cm.CreationName + ", HostType = " + cm.HostType);  
        }  
Shared  Sub Main(ByVal args() As String)  
            ' The variable pkg points to the location  
            ' of the ExecuteProcess package sample   
            ' that is installed with the samples.  
            Dim pkg As String =  "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx"   

            Dim app As Application =  New Application()   
            Dim p As Package =  app.LoadPackage(pkg,Nothing)   
            Dim conns As Connections =  p.Connections   
            Dim cm As ConnectionManager  
            For Each cm In conns  
                Console.WriteLine("Name = " + cm.CreationName + ", HostType = " + cm.HostType)  
            Next  
End Sub  

示例输出:

Name = FILE, HostType = ConnectionManager

Name = OLEDB, HostType = ConnectionManager

Name = OLEDB, HostType = ConnectionManager

注解

连接管理器为任务提供基础数据存储的泛型接口,以便实现更简单的任务。 AcquireConnection使用对象的方法ConnectionManager从集合中的任何连接管理器对象检索必要的连接信息。

连接管理器可以通过 GUID 或名称引用,并且可以将连接管理器的名称存储在配置文件中。 若要按名称引用连接,请使用 \Package.Connections[myConnection].ConnectionString,而不是使用 \Package.Connections[{9930DA64-A413-4286-9C66-74EDADB4F393}].ConnectionString

有关连接和连接管理器的详细信息,请参阅 Integration Services (SSIS) Connections

适用于