473,785 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.InvalidC astException: Cast from type 'Object()' to type 'String' is
not valid.
at Microsoft.Visua lBasic.Compiler Services.String Type.FromObject (Object
Value)
at LDAPaddin.frmDa ta.Button1_Clic k_1(Object sender, EventArgs e) in C:\VB
Projects\LDAPad din\frmData.vb: line 337
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.Button.On MouseUp(MouseEv entArgs mevent)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr 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.EventArg s) Handles Button1.Click

Dim entry As New
DirectoryServic es.DirectoryEnt ry("LDAP://server.example. com:389/ou=People,dc=cc s,dc=nrl,dc=nav y,dc=mil")

Dim mySearcher As New System.Director yServices.Direc torySearcher(en try)

Dim result As System.Director yServices.Searc hResult

Dim systemDirectory , systemService, Read1 As String

Dim Exists As Boolean

Dim Data1S, Data2S, Data3S, Data4S, Data5S, Data6S, Data7S As Object

systemDirectory = System.Environm ent.SystemDirec tory

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 = "departmentNumb er"

sField4 = "buildingNa me"

sField5 = "roomNumber "

sField6 = "telephoneNumbe r"

sField7 = "mail"

sField8 = "employeeTy pe"

Me.DataSet11.Cl ear()

Me.OleDbDataAda pter1.Update(Me .DataSet11.Empl oyees)

Me.PBar1.Visibl e = True

mySearcher.Filt er = ("" & sField2 & "=" & val2 & "")

For Each result In mySearcher.Find All

'On Error Resume Next

Data1 = (result.GetDire ctoryEntry().Pr operties("uid") .Value)

Data2 = (result.GetDire ctoryEntry().Pr operties("cn"). Value)

Data3 = (result.GetDire ctoryEntry().Pr operties("depar tmentNumber").V alue)

Data4 = (result.GetDire ctoryEntry().Pr operties("build ingName").Value )

Data5 = (result.GetDire ctoryEntry().Pr operties("roomN umber").Value)

Data6 = (result.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

Data7 = (result.GetDire ctoryEntry().Pr operties("mail" ).Value)

Data8 = (result.GetDire ctoryEntry().Pr operties("emplo yeeType").Value )

Me.DataSet11.Em ployees.AddEmpl oyeesRow(Data1, Data2, Data3, Data4, Data5,
Data6, Data7, Data8)

PBar1.PerformSt ep()

Next

PBar1.Value = 0

Me.DataSet11.Ac ceptChanges()

MsgBox("Query complete!", MsgBoxStyle.OKO nly, "")

Me.PBar1.Visibl e = False

End Sub
Nov 21 '05 #1
5 1882
Hi

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

Data6 = (result.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

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

The result.GetDirec toryEntry().Pro perties("teleph oneNumber").Val ue will
return a object array, so I think you may try assign the
result.GetDirec toryEntry().Pro perties("teleph oneNumber").Val ue 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.Em ployees.AddEmpl oyeesRow(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.InvalidC astException: Cast from type 'Object()' to type 'String' is
not valid.
at Microsoft.Visua lBasic.Compiler Services.String Type.FromObject (Object
Value)
at LDAPaddin.frmDa ta.Button1_Clic k_1(Object sender, EventArgs e) in C:\VB
Projects\LDAPad din\frmData.vb: line 424
at System.Windows. Forms.Control.O nClick(EventArg s e)
at System.Windows. Forms.Button.On Click(EventArgs e)
at System.Windows. Forms.ButtonBas e.OnKeyUp(KeyEv entArgs kevent)
at System.Windows. Forms.Control.P rocessKeyEventA rgs(Message& m)
at System.Windows. Forms.Control.P rocessKeyMessag e(Message& m)
at System.Windows. Forms.Control.W mKeyChar(Messag e& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ButtonBas e.WndProc(Messa ge& m)
at System.Windows. Forms.Button.Wn dProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
""Peter Huang" [MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:TI******** ******@TK2MSFTN GXA02.phx.gbl.. .
Hi

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

Data6 = (result.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)
'LINE 337 This field has two phone numbers ; seperated. i.e. 555 123
4567;555 765 4321

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

The result.GetDirec toryEntry().Pro perties("teleph oneNumber").Val ue will
return a object array, so I think you may try assign the
result.GetDirec toryEntry().Pro perties("teleph oneNumber").Val ue 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.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)
'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.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)
For Each o As Object In data6
Console.WriteLi ne(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.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue.GetType.ToS tring)

If TestVal1 = "System.Obj ect[]" Then

Data6 = (result.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue(0))

ElseIf TestVal1 = "System.Str ing" Then

Data6 = (result.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)

Else

End If

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

""Peter Huang" [MSFT]" <v-******@online.m icrosoft.com> wrote in message
news:Dx******** ******@TK2MSFTN GXA02.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.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)
'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.GetDire ctoryEntry().Pr operties("telep honeNumber").Va lue)
For Each o As Object In data6
Console.WriteLi ne(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
4983
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 (integrated auth) to an LDAP server which requires no login (AuthenticationTypes.None). When I run it, I get the following ambiguous error: Security Exception Description: The application attempted to perform an operation not allowed
4
27942
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 gives the following error: System.NotImplementedException: Handling of this ADSVALUE type is not yet implemented (type = 0xb). after googling for a long time i found out that many other have the same
3
2030
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 access the website and run the query from a client however the query fails to run. Someone please help? Here's the code for the query (in CheckBoxListsFill sub): 'Impersonate the Windows AD user running the application Dim impersonationContext...
1
4755
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 I have run into I am not sure how to fix, and really not sure what is causing it. Here's what is going on (test server - Windows 2003 Server): I have a page in a folder (under anonymous authentication in IIS6) that has a link on it that...
3
9880
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 seem to get this to work in VB.Net. Here's what I have: OLD ASP Code: Function Get_ADS_Users_For_Group(ADS_Path) Dim Group_Information Dim Error_Number
5
2345
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 works. I use this code to try to connect to ldap: System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(LDAP://corp.mydomain.com,user,pass); I tried using my user name and password, the domain admin...
0
365
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 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.
3
4038
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 DirectoryEntry("LDAP://server.com"); DirectorySearcher ds = new DirectorySearcher(de); de.Username = "xxx"; de.Password = "yyy"; de.AuthenticationType = AuthenticationTypes.Secure;
7
7035
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 need of a fix. I am using classic asp and making a connection to LDAP server using SQL code under IIS 5 on my localhost and it works great. I have a form and form fields that pull from active directory. Now, once I get the web team to deploy these...
3
18723
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 query test</h3>"; echo "Connecting ..."; $ds=ldap_connect("ldap.berkeley.edu"); // must be a valid LDAP server! echo "connect result is ".$ds."<p>"; if ($ds) { echo "Binding ..."; $r=ldap_bind($ds); // this is an...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9491
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.