Connections.Item[Object] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 ConnectionManager 集合中获取一个 Connections 对象。
public:
property Microsoft::SqlServer::Dts::Runtime::ConnectionManager ^ default[System::Object ^] { Microsoft::SqlServer::Dts::Runtime::ConnectionManager ^ get(System::Object ^ index); };
public Microsoft.SqlServer.Dts.Runtime.ConnectionManager this[object index] { get; }
member this.Item(obj) : Microsoft.SqlServer.Dts.Runtime.ConnectionManager
Default Public ReadOnly Property Item(index As Object) As ConnectionManager
参数
- index
- Object
要返回的 ConnectionManager 对象的名称、标识、ID 或索引。
属性值
来自集合的一个 ConnectionManager 对象。
示例
下面的代码示例使用两种方法从集合中检索项。 第一种方法使用 conns[0]
语法检索位于集合的第一位置的整个对象,并将其放入变量中 myConnMgr
。 现在可以像往常一样检索 myConnMgr
所有属性。 第二种方法使用 conns[0].<property>
语法从集合中的第一个对象检索特定属性。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
namespace Connections_Item
{
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\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";
// Create an application and load the sample.
Application app = new Application();
Package pkg = app.LoadPackage(mySample, null);
Connections conns = pkg.Connections;
//Using the Item method syntax of [x], obtain the
// entire first entry, and then just the name.
ConnectionManager myConnMgr = conns[0];
String nameOfFirstItem = conns[0].Name;
//Print the name of the connection manager located at position [0].
Console.WriteLine("The ID of the first connection info is: {0}", myConnMgr.ID);
Console.WriteLine("The Name of the first connection info is: {0}", nameOfFirstItem);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Namespace Connections_Item
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\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx"
' Create an application and load the sample.
Dim app As Application = New Application()
Dim pkg As Package = app.LoadPackage(mySample,Nothing)
Dim conns As Connections = pkg.Connections
'Using the Item method syntax of [x], obtain the
' entire first entry, and then just the name.
Dim myConnMgr As ConnectionManager = conns(0)
Dim nameOfFirstItem As String = conns(0).Name
'Print the name of the connection manager located at position [0].
Console.WriteLine("The ID of the first connection info is: {0}", myConnMgr.ID)
Console.WriteLine("The Name of the first connection info is: {0}", nameOfFirstItem)
End Sub
End Class
End Namespace
示例输出:
The ID of the first connection info is: {B52C0D78-5402-4544-BFEC-2BE203900C91}
The Name of the first connection info is: Create_Execute_Process_Dest.sql
注解
如果对方法的 Contains 调用返回 true
,则可以使用语法 Connections[index]
访问集合中的指定元素。 Contains如果该方法返回false
,此属性将引发异常。 在 C# 中,此属性是 Connections 类的索引器。