讀LDAP後 需要釋放嗎?

MStone Lin

我設計一程式
讓user輸入AD密碼後才能連接網路磁碟機
請問
讀取LDAP後需要釋放嗎?
還是沒釋放也行?


 '先驗眐密碼

        Dim iduser As String = TextBox1.Text
        Dim aduser As String = "CSHHHH\" & iduser 'System.Security.Principal.WindowsIdentity.GetCurrent().Name

        Dim ent As DirectoryEntry

        ent = New DirectoryEntry("LDAP://123.456.789.012", iduser, TextBox2.Text)

        Dim dirsearcher As DirectorySearcher
        dirsearcher = New DirectorySearcher(ent)
        dirsearcher.Filter = "(sAMAccountName=" + iduser + ")"

        dirsearcher.PropertiesToLoad.Add("displayName")

        dirsearcher.SearchScope = SearchScope.Subtree

        Try
            Dim results As SearchResult = dirsearcher.FindOne
          
            If IsNothing(results) Then
                Label3.Text = "找不到 " + TextBox1.Text + " 帳號 或 密碼錯誤。"
                Return
            Else
                Label3.Text = "密碼正確-連線中"

               '連接磁碟機

             

            End If
        Catch ex As Exception
            Label3.Text = "錯誤訊息:" + ex.Message
            Return
        Finally
           
            dirsearcher.Dispose()
            ent.Dispose()
            ent.Close()

        End Try




dirsearcher.Dispose()
ent.Dispose()
ent.Close()


這三行需要嗎?因為早上發生AD太多cache 卡住了
所以連接完要釋放!?
回到頂部