K
Kenneth H. Young
I am having difficulties with an LDAP client I'm writing. What I have
discovered causes the error is when the client queries the LDAP server and a
record contains two values entered in one field that is semicolon ";"
separated. i.e. A telephone number. In RED below.
How can I handle this?
Thanks is advance for any help.
Note: The LDAP server is not a Microsoft AD server.
Below is the
error.________________________________________________________________________________________________________
System.InvalidCastException: Cast from type 'Object()' to type 'String' is
not valid.
at Microsoft.VisualBasic.CompilerServices.StringType.FromObject(Object
Value)
at LDAPaddin.frmData.Button1_Click_1(Object sender, EventArgs e) in C:\VB
Projects\LDAPaddin\frmData.vb:line 337
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
_________________________________________________________________________________________________________
Below is the pertinent code.
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim entry As New
DirectoryServices.DirectoryEntry("LDAP://server.example.com:389/ou=People,dc=ccs,dc=nrl,dc=navy,dc=mil")
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult
Dim systemDirectory, systemService, Read1 As String
Dim Exists As Boolean
Dim Data1S, Data2S, Data3S, Data4S, Data5S, Data6S, Data7S As Object
systemDirectory = System.Environment.SystemDirectory
Dim MyFile, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8 As String
Dim val1, val2, val3, val4, val5, val6, val7, val8 As String
Dim sField1, sField2, sField3, sField4, sField5, sField6, sField7, sField8
As String
val1 = "*" 'UID
val2 = "*" 'CN value Conanicle name
val3 = "*" 'Department #
val4 = "*" 'Building #
val5 = "*" 'Room #
val6 = "*" 'Telephone #
val7 = "*" 'Email address
val8 = "*" 'Employee Type
sField1 = "uid"
sField2 = "cn"
sField3 = "departmentNumber"
sField4 = "buildingName"
sField5 = "roomNumber"
sField6 = "telephoneNumber"
sField7 = "mail"
sField8 = "employeeType"
Me.DataSet11.Clear()
Me.OleDbDataAdapter1.Update(Me.DataSet11.Employees)
Me.PBar1.Visible = True
mySearcher.Filter = ("" & sField2 & "=" & val2 & "")
For Each result In mySearcher.FindAll
'On Error Resume Next
Data1 = (result.GetDirectoryEntry().Properties("uid").Value)
Data2 = (result.GetDirectoryEntry().Properties("cn").Value)
Data3 = (result.GetDirectoryEntry().Properties("departmentNumber").Value)
Data4 = (result.GetDirectoryEntry().Properties("buildingName").Value)
Data5 = (result.GetDirectoryEntry().Properties("roomNumber").Value)
Data6 = (result.GetDirectoryEntry().Properties("telephoneNumber").Value)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321
Data7 = (result.GetDirectoryEntry().Properties("mail").Value)
Data8 = (result.GetDirectoryEntry().Properties("employeeType").Value)
Me.DataSet11.Employees.AddEmployeesRow(Data1, Data2, Data3, Data4, Data5,
Data6, Data7, Data8)
PBar1.PerformStep()
Next
PBar1.Value = 0
Me.DataSet11.AcceptChanges()
MsgBox("Query complete!", MsgBoxStyle.OKOnly, "")
Me.PBar1.Visible = False
End Sub
discovered causes the error is when the client queries the LDAP server and a
record contains two values entered in one field that is semicolon ";"
separated. i.e. A telephone number. In RED below.
How can I handle this?
Thanks is advance for any help.
Note: The LDAP server is not a Microsoft AD server.
Below is the
error.________________________________________________________________________________________________________
System.InvalidCastException: Cast from type 'Object()' to type 'String' is
not valid.
at Microsoft.VisualBasic.CompilerServices.StringType.FromObject(Object
Value)
at LDAPaddin.frmData.Button1_Click_1(Object sender, EventArgs e) in C:\VB
Projects\LDAPaddin\frmData.vb:line 337
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
_________________________________________________________________________________________________________
Below is the pertinent code.
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim entry As New
DirectoryServices.DirectoryEntry("LDAP://server.example.com:389/ou=People,dc=ccs,dc=nrl,dc=navy,dc=mil")
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult
Dim systemDirectory, systemService, Read1 As String
Dim Exists As Boolean
Dim Data1S, Data2S, Data3S, Data4S, Data5S, Data6S, Data7S As Object
systemDirectory = System.Environment.SystemDirectory
Dim MyFile, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8 As String
Dim val1, val2, val3, val4, val5, val6, val7, val8 As String
Dim sField1, sField2, sField3, sField4, sField5, sField6, sField7, sField8
As String
val1 = "*" 'UID
val2 = "*" 'CN value Conanicle name
val3 = "*" 'Department #
val4 = "*" 'Building #
val5 = "*" 'Room #
val6 = "*" 'Telephone #
val7 = "*" 'Email address
val8 = "*" 'Employee Type
sField1 = "uid"
sField2 = "cn"
sField3 = "departmentNumber"
sField4 = "buildingName"
sField5 = "roomNumber"
sField6 = "telephoneNumber"
sField7 = "mail"
sField8 = "employeeType"
Me.DataSet11.Clear()
Me.OleDbDataAdapter1.Update(Me.DataSet11.Employees)
Me.PBar1.Visible = True
mySearcher.Filter = ("" & sField2 & "=" & val2 & "")
For Each result In mySearcher.FindAll
'On Error Resume Next
Data1 = (result.GetDirectoryEntry().Properties("uid").Value)
Data2 = (result.GetDirectoryEntry().Properties("cn").Value)
Data3 = (result.GetDirectoryEntry().Properties("departmentNumber").Value)
Data4 = (result.GetDirectoryEntry().Properties("buildingName").Value)
Data5 = (result.GetDirectoryEntry().Properties("roomNumber").Value)
Data6 = (result.GetDirectoryEntry().Properties("telephoneNumber").Value)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321
Data7 = (result.GetDirectoryEntry().Properties("mail").Value)
Data8 = (result.GetDirectoryEntry().Properties("employeeType").Value)
Me.DataSet11.Employees.AddEmployeesRow(Data1, Data2, Data3, Data4, Data5,
Data6, Data7, Data8)
PBar1.PerformStep()
Next
PBar1.Value = 0
Me.DataSet11.AcceptChanges()
MsgBox("Query complete!", MsgBoxStyle.OKOnly, "")
Me.PBar1.Visible = False
End Sub