Access AD from SQL Server.

  • Experts, wondering if someone can help me with this issue I am running into. I am trying to access AD from SQL Server (working on creating AD group and granting them with access on DB instead of having hundreds of users).

    I have created a linked server and now I am running this piece of code to get info but getting an error.

    SELECT * FROM OpenQuery

    (

    ADSI,

    'SELECT streetaddress, pager, company, title, displayName, telephoneNumber, sAMAccountName,

    mail, mobile, facsimileTelephoneNumber, department, physicalDeliveryOfficeName, givenname

    FROM ''DOMAIN.com'' where objectClass = ''User'' ')

    error is:

    Msg 7321, Level 16, State 2, Line 1

    An error occurred while preparing the query "SELECT streetaddress, pager, company, title, displayName, telephoneNumber, sAMAccountName,

    mail, mobile, facsimileTelephoneNumber, department, physicalDeliveryOfficeName, givenname

    FROM 'DOMAIN.com' where objectClass = 'User' " for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".

    "He who learns for the sake of haughtiness, dies ignorant. He who learns only to talk, rather than to act, dies a hyprocite. He who learns for the mere sake of debating, dies irreligious. He who learns only to accumulate wealth, dies an atheist. And he who learns for the sake of action, dies a mystic."[/i]

  • Take a look at this[/url]. Looks like you haven't got your LDAP details all present and in the correct format.

    John

  • This is a handy guide to querying LDAP from SQL Server (and other places).

    The gist is that your SELECT statement needs to include the full LDAP://OU=??,DC=DOMAIN,DC=COM path as the FROM clause, whereas you're just supplying DOMAIN.COM.

    Thomas Rushton
    blog: https://thelonedba.wordpress.com

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

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