Query Active Directory with SQL Server

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!
blouckswwuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grayeCommented:
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
blouckswwuAuthor Commented:
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
grayeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

blouckswwuAuthor Commented:
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
grayeCommented:
Relax... it's not about points.   I bet we can figure this out.

What error are you getting?
0
blouckswwuAuthor Commented:
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
blouckswwuAuthor Commented:
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
jwarnkenCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Operating Systems

From novice to tech pro — start learning today.