472,371 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

LDAP query error

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(MouseEventAr gs 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(M essage& 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").Valu e)

Data2 = (result.GetDirectoryEntry().Properties("cn").Value )

Data3 = (result.GetDirectoryEntry().Properties("department Number").Value)

Data4 = (result.GetDirectoryEntry().Properties("buildingNa me").Value)

Data5 = (result.GetDirectoryEntry().Properties("roomNumber ").Value)

Data6 = (result.GetDirectoryEntry().Properties("telephoneN umber").Value)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

Data7 = (result.GetDirectoryEntry().Properties("mail").Val ue)

Data8 = (result.GetDirectoryEntry().Properties("employeeTy pe").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
Nov 21 '05 #1
5 1805
Hi

Based on my understanding the exception will occur when we call the line
below, if I have any misunderstanding, please feel free to post here.

Data6 = (result.GetDirectoryEntry().Properties("telephoneN umber").Value)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

From the MSDN the Properties("xxxx").Value should be object type.
Also from the callstack,
System.InvalidCastException: Cast from type 'Object()' to type 'String' is
not valid.

The result.GetDirectoryEntry().Properties("telephoneNu mber").Value will
return a object array, so I think you may try assign the
result.GetDirectoryEntry().Properties("telephoneNu mber").Value to an object
array to see if that works or an object to see if that works.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2
Thanks for the reply. This is driving me insane! If I Dim DataX as
Object and run the query it returns every field excluding ones with two
entries. For entries with two telephoneNumber numbers that are ";"
separated I get no return. If I rem "'On error Resume Next" I get the
following exception on line 424.

Line 424:
Me.DataSet11.Employees.AddEmployeesRow(Data1, Data2, Data3, Data4, Data5,
Data6, Data7, Data8)
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
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 424
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.OnKeyUp(KeyEventAr gs kevent)
at System.Windows.Forms.Control.ProcessKeyEventArgs(M essage& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Mes sage& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
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(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:TI**************@TK2MSFTNGXA02.phx.gbl...
Hi

Based on my understanding the exception will occur when we call the line
below, if I have any misunderstanding, please feel free to post here.

Data6 = (result.GetDirectoryEntry().Properties("telephoneN umber").Value)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

From the MSDN the Properties("xxxx").Value should be object type.
Also from the callstack,
System.InvalidCastException: Cast from type 'Object()' to type 'String' is
not valid.

The result.GetDirectoryEntry().Properties("telephoneNu mber").Value will
return a object array, so I think you may try assign the
result.GetDirectoryEntry().Properties("telephoneNu mber").Value to an
object
array to see if that works or an object to see if that works.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #3
Hi

From the call stack I assume one of the parameters is of type Object array.
Here I assume it is Data6 because of
Data6 = (result.GetDirectoryEntry().Properties("telephoneN umber").Value)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

So I think you may try to parse the data6 using the array syntax.
dim data6() as object
data6= (result.GetDirectoryEntry().Properties("telephoneN umber").Value)
For Each o As Object In data6
Console.WriteLine(o.ToString())
Next

You may have a try and let me know the result.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4
OK, that didn't work either but it put me on the right track.
This is what has finally worked: Don't know if it's the best way but it
works!

I'd also like to extend my gratitude to you for all your help.
Thanks for helping out a novice. :-)

Dim TestVal1, Data6 as String
TestVal1 =
(result.GetDirectoryEntry().Properties("telephoneN umber").Value.GetType.ToString)

If TestVal1 = "System.Object[]" Then

Data6 = (result.GetDirectoryEntry().Properties("telephoneN umber").Value(0))

ElseIf TestVal1 = "System.String" Then

Data6 = (result.GetDirectoryEntry().Properties("telephoneN umber").Value)

Else

End If

Note: This pulls back only the first number which is all I am intersted in.

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:Dx**************@TK2MSFTNGXA02.phx.gbl...
Hi

From the call stack I assume one of the parameters is of type Object
array.
Here I assume it is Data6 because of
Data6 = (result.GetDirectoryEntry().Properties("telephoneN umber").Value)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

So I think you may try to parse the data6 using the array syntax.
dim data6() as object
data6= (result.GetDirectoryEntry().Properties("telephoneN umber").Value)
For Each o As Object In data6
Console.WriteLine(o.ToString())
Next

You may have a try and let me know the result.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #5
Hi

I am glad that works for you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jeremy | last post by:
Hello. I have an asp.net application that resides on a non-DC / BDC Sharepoint Server (although it is logged into the domain). The application will perform lookups based on the current user...
4
by: m96 | last post by:
hi, i'm trying to make a query to a ldap server (version v2 or v3 doen't matter) with c#. the query works just fine but the problem is that i can't read the custom attributes/fields, since .net...
3
by: Jay | last post by:
I have a simple LDAP query (grabs all users from a particular AD group and populates a checkboxlist) that works perfectly fine on the development machine logged on locally as any user. When I...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
3
by: Chad Beckner | last post by:
I am starting to translate some code from ASP to ASP.NET (VB). I was able to query ADS to get a users groups that they belong to, and also query a group and get a list of users. However, I can't...
5
by: Bryan | last post by:
Hello, I have a asp.net app working with directory services on my Windows XP development machine. However when I moved the application over to our production server (Win 2000 Server) it no longer...
0
by: Kenneth H. Young | last post by:
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...
3
by: RJN | last post by:
Hi I've written a code that queries Windows LDAP server and works fine, but the same doesn't work when querying Solaris LDAP server. DirectoryEntry de = new...
7
by: MrHelpMe | last post by:
Sorry everyone, NOTE: I have posted this question to another site but unfortunately, am not getting the answers I need only because those helping haven't worked with ASP. I am in desperate...
3
by: eleland | last post by:
I am trying to bind to an LDAP server using php without success. I have a linux server running php compiled with open ldap. I am using the following code taken right from php.net: echo "<h3>LDAP...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.