I'm using .NET 3.5 and have build a successful LDAP lookup Function to consult users'data on a Sun LDAP server.
But, there is one particular record (so far) that is failing when it's being looked up.
When the Findone method is called , i get an 'Year, Month and Day Parameters describe an un-representable DateTime' error.
Now, looking at the record in particular with an LDAP browser, say Softerrra, i can see this particular record is missing data in a particular attribute (baLastupdate field).
This field is of a date/time kind so i understand i'm getting an error thrown because the NULL field is not interpreted correctly as a date/time field.
My Question is:how can i intercept this error so that it doesn't crash and thus if the field is blank, doesn't crash out on me. I 'm not defining anywhere what fields the LDAP system will provide nor what type of fields there are.
I've got my LDAPconnection set up as follows
Public Class LDAPDirectorySearcher
Private Shared LDAPDirEntry As System.DirectoryServices.DirectoryEntry
Private Shared LDAPDirSearcher As DirectorySearcher
Public Shared Function DirSearcherSetup() As DirectorySearcher
Try
LDAPDirEntry = New DirectoryEntry
LDAPDirEntry.Path = "LDAP://aaaa.bbbbb.ccccc.com/ou=people"
LDAPDirEntry.Username = "yyyyyyyyyyy"
LDAPDirEntry.Password = "xxxxxx"
LDAPDirEntry.AuthenticationType = AuthenticationTypes.FastBind
LDAPDirSearcher = New DirectorySearcher(LDAPDirEntry)
LDAPDirSearcher.CacheResults = True
Catch ex As Exception
End Try
Return LDAPDirSearcher
End Function
There's nothing wrong with the authentication or the setup or so (it works for +100K other records) but when there is no data in this date/time field, it crashes somehow.I'ld like to overcome this NULL field.
You can use the PropertiesToLoad
property to choose which properties to retrieve in the search. Note that if you later call the GetDirectoryEntry
method on the SearchResult
, it'll probably crash there, too.
You could also try the lower level System.DirectoryServices.Protocols
namespace.