Solved

Query Active Directory from SQL 2008

Posted on 2012-04-09
3
438 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
3 Comments
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now