Solved

Query Active Directory with SQL Server

Posted on 2004-09-16
8
721 Views
Last Modified: 2008-05-30
Is there any way to setup SQL Server to link to Active Directory so I can setup various reports to run automatically querying the SQL server?  I am looking for a solution that will work with my existing setup, so I do not have to purchase expensive software.

Thanks for any help!
0
Comment
Question by:blouckswwu
  • 4
  • 3
8 Comments
 
LVL 41

Expert Comment

by:graye
ID: 12077895
Sure... it's just like you'd imagine.   You create a "linked server" to point to Active Directory.

From the SQL Management Console, <server name>, Security, Linked Server, click to create a new linked server.   From the list of providers, pick "OLEDB Provider for Microsoft Directory Services"... fill out the appropriate info, and you're cooking.

The tables under this linked server are called like this in TransactSQL:

         AD...TableName

(Where AD is the name of the linked server)
0
 

Author Comment

by:blouckswwu
ID: 12078384
So what do put in the other fields?

Product Name: (??)
Data Source: (servername of my Active Directory Master Browser)
Provider String: (??)
Location: (??)

I'm sorry if these seem like stupid questions, but I can't seem to find any information on how to set this up.

Thanks for your help!!
0
 
LVL 41

Accepted Solution

by:
graye earned 400 total points
ID: 12080128
You can leave a bunch of those fields blank (I usually do... I'm not actually sure what they're for!)

I'm not at an Active Directory setup right now... and I can't find any examples using the Management Console.  If I remember correcly... you don't have to put anything in there except the name of the linked server.

I did find an an article on how to do it all from the command-line  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_qd_12_94fn.asp
0
 

Author Comment

by:blouckswwu
ID: 12080259
I must be missing something here.  I followed the msdn article to a 'T' and I still get a damn error.  I am using Windows Auth and I am a Domain Admin.  But I still get this same error everytime.  I was assuming that this was not rocket science, but I assumed wrong.  Its frustrating to have all this information in a Database (Active Directory) and I can't get it out easly and Microsoft doesn't put out hardly any information on how to get it out.  That one link you gave me was the only real document that shows that it can be done and its one little page.  Sorry just frustrated.  If you can get a chance to test it and figure out what I am doing wrong, I will give you  1500 points, as I have 3 entries out on different sections regarding this.

Thanks again
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 41

Expert Comment

by:graye
ID: 12083379
Relax... it's not about points.   I bet we can figure this out.

What error are you getting?
0
 

Author Comment

by:blouckswwu
ID: 12083727
Sorry...had a long day yesterday.  Here is the error:

Error 7301: Could not obtain a required interface from OLE DB provider 'ADsDSOObject'.
OLE DB error trace [OLE/DB Provider 'ADsDSOObject' IUnknown::QueryInterface returned 0x80004002:  IDBSchemaRowset].

I have looked up that error code on google and got nothing worth looking at.  I'm wondering if this has something to do with permissions?  I am wondering what login SQL server is using to connect to Active Directory?  I would assume that you would have to be a domain admin to be able to connect.  I looked at the security tab and tried different settings, but couldn't get anything to work.

Thanks
0
 

Author Comment

by:blouckswwu
ID: 12083804
Ok...on one of my other post I got this solution:

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20429310.html

I followed it and I get this error when I run the query (the one with the accepted answer):

Server: Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing a query for execution against OLE DB provider 'ADSDSOObject'.
OLE DB error trace [OLE/DB Provider 'ADSDSOObject' ICommandPrepare::Prepare returned 0x80040e14].

Here is the query:
--Create the Link to Active Directory
EXEC sp_addlinkedserver 'ADSI2', 'Active Directory
Services 2.0', 'ADSDSOObject', 'adsdatasource'
Go

--Create a login entry (not sure what this is for, since it looks like its putting in nulls)
EXEC sp_addlinkedsrvlogin ADSI2, false, null, null, null
Go

--Actual Query
SELECT *
FROM OpenQuery( ADSI2, 'SELECT name, adsPath
                   FROM ''LDAP://DC=am1st,DC=com''
                   WHERE objectCategory = ''Person'' AND objectClass= ''user''')

Thanks
0
 
LVL 8

Assisted Solution

by:jwarnken
jwarnken earned 100 total points
ID: 12084440
I do not know it this will help but I use a vbscript to query AD.
check out http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/sas_ads_overview.mspx for a overview to script a query it may point you in the right direction.

good luck
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

920 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

14 Experts available now in Live!

Get 1:1 Help Now