다음을 통해 공유


연결 캐싱

서버에 연결이 이루어지면 연결 핸들은 해당 연결이 종료될 때까지 해당 프로세스에 대해 클라이언트 컴퓨터에 캐시됩니다. 후속 연결에서 동일한 서버, 포트 및 자격 증명을 사용하고 ADS_FAST_BIND 또는 ADS_SERVER_BIND 인증 플래그만 다른 경우 ADSI는 기존 연결을 다시 사용합니다. ADSI는 프로세스별로 이 연결 캐싱을 수행합니다.

성능을 향상시키려면 가능한 경우 기존 연결을 다시 사용합니다.

다음은 Visual Basic에서 IAD를 사용하는 예제입니다(IAD 인터페이스 사용도 참조).

Dim cachedConn As IADs
Dim obj As IADs
Dim cachedName As String
Dim objName As String
 
' Connect to the server and maintain this handle to cache the connection.
Set cachedConn = GetObject("LDAP://MyMachine/DC=MyDomain,DC=Fabrikam,DC=com")
 
cachedName = cachedConn.Get("distinguishedName")
Debug.Print (cachedName)
 
' Reuse the connection to MyMachine opened by cachedConn.
' Be aware that this line executes quickly because it is not required
' to transmit over the network again.
Set obj = GetObject("LDAP://MyMachine/CN=Bob,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com")
 
objName = obj.Get("distinguishedName")
Debug.Print (objName)
 
' Release the second connection.
Set obj = Nothing
 
' Reuse the connection to MyMachine opened by cachedConn again.
Set obj = GetObject("LDAP://MyMachine/CN=Administrator,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com")
 
objName = obj.Get("distinguishedName")
Debug.Print (objName)
 
' Release the second connection again.
Set obj = Nothing
 
' Release the first connection.
Set cachedConn = Nothing
 
' The connection to MyMachine is closed.

다음 대체 예제에서는 .NET의 DirectoryEntry 개체를 사용하여 연결 캐싱이 작동하는 방법을 보여 줍니다.

// Connect to the server and maintain this handle to cache the connection.
using (DirectoryEntry? cachedConn = new DirectoryEntry("LDAP://MyMachine/DC=MyDomain,DC=Fabrikam,DC=com")) 
{
    DirectoryEntry? secondConn;
    string? cachedName;
    string? objName;

    cachedName = cachedConn.Properties["distinguishedName"].Value?.ToString();
    Debug.WriteLine(cachedName);

    // Reuse the connection to MyMachine opened by cachedConn.
    // Be aware that this line executes quickly because it is not required
    // to transmit over the network again.
    using (secondConn = new DirectoryEntry("LDAP://MyMachine/CN=Bob,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com"))
    {
        objName = secondConn.Properties["distinguishedName"].Value?.ToString();
        Debug.WriteLine(objName);

        // Release the second connection.
        secondConn = null;

        // Reuse the connection to MyMachine opened by cachedConn again.
        secondConn = new DirectoryEntry("LDAP://MyMachine/CN=Administrator,CN=Users,DC=MyDomain,DC=Fabrikam,DC=com");

        objName = secondConn.Properties["distinguishedName"].Value?.ToString();
        Debug.WriteLine(objName);
    }
    // Release and dispose the second connection
}
// The connection to MyMachine is closed and disposed

참고 항목

DirectoryEntry

IAD 인터페이스 사용