Solved

Query Active Directory from SQL 2008

Posted on 2012-04-09
3
442 Views
Last Modified: 2012-05-23
I set up a  linked server to the active directory using the following code:

EXEC master.dbo.sp_addlinkedserver @server = N'ADSI',
@srvproduct=N'Active Directory Services', @provider=N'ADsDSOObject',
@datasrc=N'ServerName.Domain'

Open in new window


I get a linked server. I can right click and test connection with an affirmative response. Then I click through to try and see the tables and I get the message in the attachment. When I try to run a query using this:

select  * 
from  openquery(ADSI, ' 
select  title, sAMAccountName, displayName, userAccountControl
from    ''LDAP://DC=ServerName.Domain,DC=COM'' ') 

Open in new window


I get the following message:

Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT sAMAccountname,givenname,sn,displayname,useraccountcontrol,CN
FROM 'LDAP://DC=ServerName.Domain,DC=COM'
WHERE objectCategory='person' AND objectClass='user'
ORDER BY CN" for execution against OLE DB provider "ADsDSOObject" for linked server "ADSI".

The "ServerName.Domain" is the name of the server on which active directory resides and the domain is the name of the network domain.

I added the network administrator as the remote login. I'm out of ideas as to why this is not working.
Capture.JPG
0
Comment
Question by:jczander
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
ID: 37827245
If your domain is, say, inter.mydomain.com, then the 4th line of your code should be

from    ''LDAP://dc=inter,dc=mydomain,dc=com'' ')

ServerName shouldn't be in the picture.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question