January 9, 2017 at 9:07 am
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]
January 9, 2017 at 9:18 am
January 9, 2017 at 9:30 am
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