How to connect to a SQL Server via LDAP

  • I have very unusual question. I have seen a query that looks something like this:

    SELECT A, B, C FROM 'LDAP://abc.def.com'

    What exactly does this mean? Could such a query be executed in the SQL Server Management Studio? Where would such a table/database be actually located?

  • One bit of information, this query is used to read the active directory.

  • This link below gave me some ideas when I was putting together a query.

    http://stackoverflow.com/questions/407671/query-ad-from-sql-server-2005

    This is a query I actually got to work at my place, what I found interesting is that selecting with a '*' instead of an explicit column list returned entirely different stuff whereas I expected the '*' would just send back all columns, but instead it returned a list of ldap urls, which makes me think SQL Server actually passes the query through to the ldap / ad server with much less processing than I would have figured (in other words, * does NOT mean all the columns in this case). But the (commented) select with the list of columns also worked and returned the three columns as expected.

    SELECT top 100 *

    --SELECT top 100 [Name], SN [Last Name], ST State

    FROM OPENQUERY( ADSI,

    'SELECT *

    FROM ''LDAP://a_local_active_directory_server''

    WHERE objectCategory=''user''

    ')

    edit: I also had to add in a linked server, forgot to add this!

    EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services Interfaces','ADSDSOObject', 'adsdatasource'

    The version with the explicitely named columns:

    SELECT top 100 [Name], SN [Last Name], ST State

    FROM OPENQUERY( ADSI,

    'SELECT Name, SN, ST

    FROM ''LDAP://active_directory_server''

    WHERE objectCategory=''user''

    ')

  • thank you for the explanation. I did not pick up on the linked server. I suppose the linked server connect to the active directory data store against which the query is running.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply