LDAP connection Attempted to read or write protected memory error

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Dear all,
I have this piece of code to access LDAP and its working fine.
The only question I have is, this pcs of code is run on form load. If I close the form again and open the form again. It gives me this error
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
May I know what causing this error? Dim oSearcher As New DirectorySearcher
Dim oResults As SearchResultCollection
Dim RetArray As New ArrayList
Dim ResultFields() As String = {"securityEquals", "cn"}
Dim result As New List(Of String)
Dim objGroupEntry As DirectoryEntry



oSearcher.SearchRoot = New DirectoryEntry(LDAP_SERVER, LDAP_ID, LDAP_PASS)
oSearcher.PropertiesToLoad.AddRange(ResultFields)
oSearcher.Filter = "(&(objectClass=user))"

oResults = oSearcher.FindAll()



If (oResults.Count <> 0) Then
For Each mySearchResult As SearchResult In oResults
objGroupEntry = mySearchResult.GetDirectoryEntry()
result.Add(objGroupEntry.Name)

Dim newRow As DataRow = dt_trainerTemp.NewRow
newRow("NAME") = objGroupEntry.Properties("cn").Value.ToString
If objGroupEntry.Properties("mail").Value = Nothing Then
newRow("EMAIL") = ""
Else
newRow("EMAIL") = objGroupEntry.Properties("mail").Value.ToString
End If
dt_trainerTemp.Rows.Add(newRow)
newRow = Nothing
Next
End If

For Each eachRow In dt_trainerTemp.Rows
Dim newRow As DataRow = dt_trainer.NewRow
newRow("NAME") = eachRow("NAME")
newRow("EMAIL") = eachRow("EMAIL")
dt_trainer.Rows.Add(newRow)
Next



oSearcher.Dispose()
oResults.Dispose()
objGroupEntry.Dispose()

oSearcher = Nothing
oResults = Nothing
objGroupEntry = Nothing
RetArray = Nothing
ResultFields = Nothing
result = Nothing

View the full article
 
Back
Top