Forum Search:
Forum.Brain-Cluster.com: Brain Cluster Technical Forum
Ultimate forum for Technical Discussions

Home » Microsoft » Windows Server » Active Directory » LDAP error
LDAP error [message #397102] Mon, 22 February 2010 06:06 Go to next message
eric[1]  is currently offline eric[1]
Messages: 180
Registered: July 2009
Senior Member
Hi,

I'm testing a LDAP connection to my companies Active directory server and
I'm getting the "An invalid dn syntax has been specified." error all the time.

Here is my code:

Dim entry As New DirectoryEntry()
entry.Path = "LDAP://xxxxxx.company.se:389"
entry.Username = "uid=MYAPP,ou=users,ou=internal,o=company"
entry.Password = "yyyyyyyyy"
entry.AuthenticationType = AuthenticationTypes.Secure

Dim search As New DirectorySearcher(entry)
search.ExtendedDN = ExtendedDN.Standard

search.Filter = "(&(ou=ENN)(eriIsManager=Y))"

search.PropertiesToLoad.Clear()
search.PropertiesToLoad.Add("uid")
search.PropertiesToLoad.Add("eriCn")
search.PropertiesToLoad.Add("mail")
search.PropertiesToLoad.Add("title")
search.PropertiesToLoad.Add("eriResignDate")
search.SearchScope = SearchScope.OneLevel

Dim sr As SearchResultCollection
Dim x As String = ""
Dim sw As New
streamwriter(My.Computer.FileSystem.SpecialDirectories.Deskt op +
"\ldaptest.txt")

sr = search.FindAll
For Each src As SearchResult In sr
For Each strKey As String In src.Properties.PropertyNames
Dim objValueCollection As ResultPropertyValueCollection
objValueCollection = src.Properties(strKey)
Dim objPropertyValue As Object
For Each objPropertyValue In objValueCollection
x += objPropertyValue.ToString + ";"
Next
Next strKey
sw.WriteLine(x)
Next

sw.Close()
entry.Close()

with this code I'm trying to figure out how to read the returned data.
The error message always comes on the FindAll line.

I have used the same settings in Apache Directory Studio and then it works.

what am I doing wrong?

rg,
Eric
Re: LDAP error [message #397126 is a reply to message #397102] Mon, 22 February 2010 06:39 Go to previous messageGo to next message
pbbergs  is currently offline pbbergs  United States
Messages: 1024
Registered: July 2009
Senior Member
I don't know if this is it or not but I believe your
entry.Username = "uid=MYAPP,ou=users,ou=internal,o=company"

Should read more like
entry.Username = "cn=MYAPP,ou=users,ou=internal,o=company"

--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.

"Eric" <Eric@discussions.microsoft.com> wrote in message
news:F4F6F5F4-F7B2-4165-951E-56A7DED3F08A@microsoft.com...
> Hi,
>
> I'm testing a LDAP connection to my companies Active directory server and
> I'm getting the "An invalid dn syntax has been specified." error all the
> time.
>
> Here is my code:
>
> Dim entry As New DirectoryEntry()
> entry.Path = "LDAP://xxxxxx.company.se:389"
> entry.Username = "uid=MYAPP,ou=users,ou=internal,o=company"
> entry.Password = "yyyyyyyyy"
> entry.AuthenticationType = AuthenticationTypes.Secure
>
> Dim search As New DirectorySearcher(entry)
> search.ExtendedDN = ExtendedDN.Standard
>
> search.Filter = "(&(ou=ENN)(eriIsManager=Y))"
>
> search.PropertiesToLoad.Clear()
> search.PropertiesToLoad.Add("uid")
> search.PropertiesToLoad.Add("eriCn")
> search.PropertiesToLoad.Add("mail")
> search.PropertiesToLoad.Add("title")
> search.PropertiesToLoad.Add("eriResignDate")
> search.SearchScope = SearchScope.OneLevel
>
> Dim sr As SearchResultCollection
> Dim x As String = ""
> Dim sw As New
> streamwriter(My.Computer.FileSystem.SpecialDirectories.Deskt op +
> "\ldaptest.txt")
>
> sr = search.FindAll
> For Each src As SearchResult In sr
> For Each strKey As String In src.Properties.PropertyNames
> Dim objValueCollection As ResultPropertyValueCollection
> objValueCollection = src.Properties(strKey)
> Dim objPropertyValue As Object
> For Each objPropertyValue In objValueCollection
> x += objPropertyValue.ToString + ";"
> Next
> Next strKey
> sw.WriteLine(x)
> Next
>
> sw.Close()
> entry.Close()
>
> with this code I'm trying to figure out how to read the returned data.
> The error message always comes on the FindAll line.
>
> I have used the same settings in Apache Directory Studio and then it
> works.
>
> what am I doing wrong?
>
> rg,
> Eric
Re: LDAP error [message #397127 is a reply to message #397102] Mon, 22 February 2010 06:46 Go to previous messageGo to next message
florian  is currently offline florian  Switzerland
Messages: 484
Registered: July 2009
Senior Member
Eric,

Eric wrote:
> I'm testing a LDAP connection to my companies Active directory server and
> I'm getting the "An invalid dn syntax has been specified." error all the time.
>
> Here is my code:
>
> Dim entry As New DirectoryEntry()
> entry.Path = "LDAP://xxxxxx.company.se:389"
> entry.Username = "uid=MYAPP,ou=users,ou=internal,o=company"
> entry.Password = "yyyyyyyyy"
> entry.AuthenticationType = AuthenticationTypes.Secure

UID won't work, you'll need the CN= prefix for a user name and the other
path parts accordingly. What's your domain name? The path should read
something like CN=myAppAccount,OU=Users,DC=domain,DC=tld. Note that if
"Users" is the built-in container rather than an organizational unit,
you'd specify that "Users" container as CN=Users rather than OU=users.

A different approach could be just specifying the user via its SID or
the object GUID -- not sure how .NET would handle that/how it's handled.

Cheers,
Florian
Re: LDAP error [message #397331 is a reply to message #397127] Mon, 22 February 2010 10:54 Go to previous messageGo to next message
eric[1]  is currently offline eric[1]
Messages: 180
Registered: July 2009
Senior Member
Hi,

I don't think that is it, because in Apache Directory Studio I use the same
dn for the user login as below and there is works.

it must be something else, not?

rg,
Eric


"Florian Frommherz [MVP]" wrote:

> Eric,
>
> Eric wrote:
> > I'm testing a LDAP connection to my companies Active directory server and
> > I'm getting the "An invalid dn syntax has been specified." error all the time.
> >
> > Here is my code:
> >
> > Dim entry As New DirectoryEntry()
> > entry.Path = "LDAP://xxxxxx.company.se:389"
> > entry.Username = "uid=MYAPP,ou=users,ou=internal,o=company"
> > entry.Password = "yyyyyyyyy"
> > entry.AuthenticationType = AuthenticationTypes.Secure
>
> UID won't work, you'll need the CN= prefix for a user name and the other
> path parts accordingly. What's your domain name? The path should read
> something like CN=myAppAccount,OU=Users,DC=domain,DC=tld. Note that if
> "Users" is the built-in container rather than an organizational unit,
> you'd specify that "Users" container as CN=Users rather than OU=users.
>
> A different approach could be just specifying the user via its SID or
> the object GUID -- not sure how .NET would handle that/how it's handled.
>
> Cheers,
> Florian
> .
>
Re: LDAP error [message #397542 is a reply to message #397331] Mon, 22 February 2010 14:44 Go to previous messageGo to next message
Florian Frommherz  is currently offline Florian Frommherz  Germany
Messages: 86
Registered: February 2010
Member
Howdie!

Am 22.02.2010 18:54, schrieb Eric:
> I don't think that is it, because in Apache Directory Studio I use the same
> dn for the user login as below and there is works.

We're talking about AD here, right? If this is AD or LDS, you'll need to
specify the path like this. I think the error message is clear about that.

Cheers,
Florian
Re: LDAP error [message #397956 is a reply to message #397542] Tue, 23 February 2010 06:16 Go to previous message
pbbergs  is currently offline pbbergs  United States
Messages: 1024
Registered: July 2009
Senior Member
Agreed

--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.

"Florian Frommherz" <florian@LEAVETHISOUT.frickelsoft.net> wrote in message
news:erTU0gAtKHA.5936@TK2MSFTNGP04.phx.gbl...
> Howdie!
>
> Am 22.02.2010 18:54, schrieb Eric:
>> I don't think that is it, because in Apache Directory Studio I use the
>> same
>> dn for the user login as below and there is works.
>
> We're talking about AD here, right? If this is AD or LDS, you'll need to
> specify the path like this. I think the error message is clear about that.
>
> Cheers,
> Florian
Previous Topic:Lingering Objects -tips?
Next Topic:AD 8606 error
Goto Forum:
  


Current Time: Wed Jan 17 04:14:27 MST 2018

Total time taken to generate the page: 0.02927 seconds
.:: Contact :: Home ::Sitemap::.

Powered by: FUDforum 3.0.0RC2.
Copyright ©2001-2009 FUDforum Bulletin Board Software