Solved

Query Active Directory from SQL 2008

Posted on 2012-04-09
3
440 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 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