Hallo
ich hoffe ihr könnt mir helfen. Ich hole aus einem LDAP Verzeichnis alle Daten raus. Das sind in etwa 30.000 Einträge. Diese werden dann in eine Text Datei gespeichert.
Jedenfalls beim abrufen der Felder steigt der Speicher unheimlich an und irgendwann so bei 1.5 GB Speicherauslastung gibt Windows auf. Logisch.
Wie kann ich das umgehen.
Anbei das Script.
Public Sub GetAllUsers(ByVal ldapServerName As String, ByVal ldapPfad As _
String, Optional ByVal ldapUser As String = "", Optional ByVal ldapPassw As _
String = "")
Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & _
ldapServerName & ldapPfad, ldapUser, ldapPassw, _
AuthenticationTypes.ServerBind)
Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
'Dim x As Integer
'For x = 0 To 28
Dim oResults As SearchResultCollection
Dim oResult As SearchResult
oSearcher.Filter = "sn=*" 'key(x)
oSearcher.SearchScope = SearchScope.OneLevel
oSearcher.PropertiesToLoad.Add("cn")
Dim i As Long
Try
System.Console.WriteLine("Verbindung zur Datenbank wird geöffnet" & _
"und Anzahl der Einträge wird ausgelesen")
oResults = oSearcher.FindAll
anzahl = oResults.Count
i = 0
For Each oResult In oResults
i = i + 1
sn = ""
mail = ""
fax = ""
loc = ""
departName = ""
departNumber = ""
mobile = ""
telephoneNumber = ""
homePhone = ""
givenName = ""
If Not oResult.GetDirectoryEntry().Properties("sn").Value = "" _
Then
sn = Left(oResult.GetDirectoryEntry().Properties( _
"sn").Value, 64)
End If
If Not oResult.GetDirectoryEntry().Properties("mail").Value = _
"" Then
mail = Left(oResult.GetDirectoryEntry().Properties( _
"mail").Value, 32)
End If
If Not oResult.GetDirectoryEntry().Properties( _
"givenName").Value = "" Then
givenName = Left(oResult.GetDirectoryEntry().Properties( _
"givenName").Value, 64)
End If
If Not oResult.GetDirectoryEntry().Properties( _
"facsimileTelephoneNumber").Value = "" Then
fax = Left(oResult.GetDirectoryEntry().Properties( _
"facsimileTelephoneNumber").Value, 32)
End If
If Not oResult.GetDirectoryEntry().Properties("l").Value = "" _
Then
loc = Left(oResult.GetDirectoryEntry().Properties( _
"l").Value, 255)
End If
If Not oResult.GetDirectoryEntry().Properties( _
"mlhOuName").Value = "" Then
departName = Left(oResult.GetDirectoryEntry().Properties( _
"mlhOuName").Value, 255)
End If
If Not oResult.GetDirectoryEntry().Properties( _
"departmentNumber").Value = "" Then
departNumber = Left(oResult.GetDirectoryEntry().Properties( _
"departmentNumber").Value, 255)
End If
If Not oResult.GetDirectoryEntry().Properties("mobile").Value = _
"" Then
mobile = Left(oResult.GetDirectoryEntry().Properties( _
"mobile").Value, 32)
End If
If Not oResult.GetDirectoryEntry().Properties( _
"telephoneNumber").Value = "" Then
telephoneNumber = Left(oResult.GetDirectoryEntry( _
).Properties("telephoneNumber").Value, 32)
End If
If Not oResult.GetDirectoryEntry().Properties( _
"homePhone").Value = "" Then
homePhone = Left(oResult.GetDirectoryEntry().Properties( _
"homePhone").Value, 32)
End If
If Not sn = "" Then
writeCTImportFile(sn, , givenName, , , , departName, _
departNumber, loc, , , , , , , , , , , , , , , , , , , _
telephoneNumber, , , , , , , , , mobile, , , , , , , , , _
fax, , , , , , , , , mail, , , , , , , , , homePhone, , , _
)
End If
Next oResult
Catch e As Exception
writeLog("GetAllUsers", i & " von " & anzahl & " Einträge" & _
"ausgelesen und geschrieben!")
writeLog("GetAllUsers", e.Message)
Finally
oSearcher.Dispose()
oResults.Dispose()
End Try
'Next
End Sub Gruß Henning |