locked
ldap queries in sql format RRS feed

  • Question

  • User-59642099 posted

    Hi,

    I'm very new to the ldap and .net, and have logged countless hours this last week trying figure this stuff you. You will be proud to know that with this website and other resources I have finally connected and am pulling info out of the directory. Whew...but....

    I have an older code example (asp 3.0) that shows the queries being done in sql syntax. This is much easier than what I have seen so far. Here is an example:

    Dim oCon

    Dim oCmd

    Dim oRs

    oCon = Server.CreateObject("ADODB.Connection")

    oCmd = Server.CreateObject("ADODB.Command")

    oCon.Provider = ("ADsDSOObject")

    oCon.Open("Active Directory Provider")

    oCmd.ActiveConnection = oCon

    oCmd.CommandText = "SELECT AdsPath FROM 'LDAP://xxx.xxx.xxx:389/ou=people,ou=intranet,dc=xxx,dc=com' WHERE uid='xxx'"

    ....blah, blah, blah

    Now ,  I can run this code in my page by selecting ASPCOMPAT="TRUE" in the page directive, but I'd like to be able to do this in .NET.

    Is there a way to query ldap in asp .net /vb .net with an sql string? Seems cleaner to me, but that's probably because I have experience with SQL and not so much with LDAP and VB .NET. Doesn't the SQL format make it easier to plug into a DATASET rather than building it manually like in the examples I have seen here?

    Thanks all for your time!

    Wednesday, March 29, 2006 1:52 AM

All replies

  • User1354132231 posted
    The SQL format embodies everything that is wrong and evil with ADO and LDAP and my eyes are burning just looking at it.  ;)

    Sorry, but the SQL format is really crappy for LDAP and you are much better off learning the simple, native format.  As you have found, the wonky SQL format is only supported using the wonky ADO recordset format, which is only supported using the wonky legacy ADO.

    The good news for you is that fixing this code is very simple and once you try it a few times you will be kicking yourself for ever thinking that the SQL paradigm fit for LDAP.  Try the first post in this forum, use a SearchRoot centered on 'OU=People,OU=Intranet,DC=xxx,DC=xxx'.  Next apply the LDAP filter of "(uid=foo)" or "(sAMAccountName=foo)" if using AD.  The 'adsPath' is automatically returned.  It is also in the SearchResult.Path or available from the 'distinguishedName' attribute in AD/ADAM.

    Friday, March 31, 2006 4:19 PM
  • User-59642099 posted
    I guess I'll have to take your word for it. I am not very experienced with this stuff. I have gotten everything working using the examples from the initial posts and some other resources. I can pull infor and authenticate. The  next step for me is to get the info into a dataset or dataform for display and/or manipulation. At first glance, it just appears SQL requires fewer lines of code to get the same info. Sorry to make your eyes burn, and thanks for the reply ;)
    Monday, April 3, 2006 1:17 PM