Connections.Contains(Object) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
예외를 발생시키지 않고 인덱싱을 사용하여 컬렉션의 ConnectionManager 항목에 액세스할 수 있는지 여부를 나타냅니다.
public:
bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean
매개 변수
- index
- Object
컬렉션에서 찾을 이름, 설명, ID 또는 인덱스입니다.
반환
구문 Connections[index]를 사용하여 컬렉션에 액세스할 수 있으면 true입니다. true이면 이름, 설명 또는 인덱스로 컬렉션에 액세스할 수 있습니다. 컬렉션에서 항목을 검색하는 데 인덱싱을 사용할 수 없으면 false입니다 Connections .
예제
다음 코드 샘플에서는 컬렉션에서 새로 추가된 ADO.NET 연결 관리자를 제거합니다. 그런 다음 이 메서드를 Contains 사용하여 연결 관리자가 제거되었는지 확인합니다.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
namespace Connections_Collection
{
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 myConns = pkg.Connections;
// Show how many connections are in the package.
int myConnsCount = myConns.Count;
Console.WriteLine("The number of connections is: {0}", myConnsCount);
// Add an OLEDB connection manager.
ConnectionManager myConn = pkg.Connections.Add("OLEDB");
myConn.Name = "My OLEDB ConnectionManager";
myConn.ConnectionString = "Data Source=.;Initial Catalog=AdventureWorks;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Auto Translate=False;";
// Verify the addition of one connection manager.
myConnsCount = myConns.Count;
Console.WriteLine("The number of connections now is: {0}", myConnsCount);
// Write out the names of the connection managers.
foreach (ConnectionManager myCMgrs in myConns)
{
Console.WriteLine("Name: {0}", myCMgrs.Name);
Console.WriteLine("ID: {0}", myCMgrs.ID);
Console.WriteLine("--------------------------------------------");
}
// Remove the connection manager by name.
pkg.Connections.Remove("My OLEDB ConnectionManager");
// Verify the removal of the connection manager.
myConnsCount = myConns.Count;
Console.WriteLine("The number of connections is finally: {0}", myConnsCount);
// Using the Contains method, verify if the connection is in the collection.
Boolean connRemoved = myConns.Contains("My OLEDB ConnectionManager");
Console.WriteLine("The connection is still in the collection? {0}", connRemoved);
Console.WriteLine();
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Namespace Connections_Collection
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 myConns As Connections = pkg.Connections
' Show how many connections are in the package.
Dim myConnsCount As Integer = myConns.Count
Console.WriteLine("The number of connections is: {0}", myConnsCount)
' Add an OLEDB connection manager.
Dim myConn As ConnectionManager = pkg.Connections.Add("OLEDB")
myConn.Name = "My OLEDB ConnectionManager"
myConn.ConnectionString = "Data Source=.;Initial Catalog=AdventureWorks;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Auto Translate=False;"
' Verify the addition of one connection manager.
myConnsCount = myConns.Count
Console.WriteLine("The number of connections now is: {0}", myConnsCount)
' Write out the names of the connection managers.
Dim myCMgrs As ConnectionManager
For Each myCMgrs In myConns
Console.WriteLine("Name: {0}", myCMgrs.Name)
Console.WriteLine("ID: {0}", myCMgrs.ID)
Console.WriteLine("--------------------------------------------")
Next
' Remove the connection manager by name.
pkg.Connections.Remove("My OLEDB ConnectionManager")
' Verify the removal of the connection manager.
myConnsCount = myConns.Count
Console.WriteLine("The number of connections is finally: {0}", myConnsCount)
' Using the Contains method, verify if the connection is in the collection.
Dim connRemoved As Boolean = myConns.Contains("My OLEDB ConnectionManager")
Console.WriteLine("The connection is still in the collection? {0}", connRemoved)
Console.WriteLine()
End Sub
End Class
End Namespace
샘플 출력:
The number of connections is: 3
The number of connections now is: 4
Name: Create_Execute_Process_Dest.sql
ID: {B52C0D78-5402-4544-BFEC-2BE203900C91}
--------------------------------------------
Name: customers
ID: {4F945623-B43F-470F-9D1E-D2A0B09177AE}
--------------------------------------------
Name: localhost.AdventureWorks
ID: {47179DDF-BD08-4E29-87C4-3A3D77105C2B}
--------------------------------------------
Name: My OLEDB ConnectionManager
ID: {90DF568E-ECB1-46D2-8DCB-3E2C67391E64}
--------------------------------------------
The number of connections is finally: 3
The connection is still in the collection? False