Solved

Querying AD

Posted on 2006-06-25
5
214 Views
Last Modified: 2012-06-27
Hi,
I have some code that is VB and is used to connect to active directory using LDAP
strSql = "Select sn, givenName, name"
strSql = strSql & "From 'LDAP://DC = Local,DC=OurPlace,DC= govt, DC=NZ' " 'rob
strSql = strSql & "WHERE objectCategory='Person' "
strSql = strSql & "AND objectClass = 'User' "

Is it possible to have this inside a stored procedure?
I tried in QA but it spews on the "FROM" line.
0
Comment
Question by:QPR
[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
  • 2
5 Comments
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 500 total points
ID: 16980718
OPENROWSET should do it.

To initially get it working you need to ditch that dynamic SQL and use query analyzer directly to test it.


I hate to be just a 'link poster' but this looks like what you're after:


http://www.dbtalk.net/microsoft-public-sqlserver-clients/ldap-openrowset-150001.html
0
 
LVL 29

Author Comment

by:QPR
ID: 16980742
Thanks, I'll check the link.
I did cut the string stuff in QA but I kept getting syntax errors for...

From LDAP://DC = Local,DC=OurPlace,DC= govt, DC=NZ
0
 
LVL 29

Author Comment

by:QPR
ID: 16980762
That almost works great.
If I just select name from etc I get that column.
Not knowing the other column names I tried a select * but got a ton of cryptic non-SQL errors.
Any idea how to retrieve the column names?
If not, I'll get the network admin to tell me.
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 16982344
FYI when a name has spaces or special characters you surround it with square brackets.

Like this:


From [LDAP://DC = Local,DC=OurPlace,DC= govt, DC=NZ]


That particular thing won't actually work, but if you ever have a strangely named table or field, just surround it with square brackets.


For PAQ reference in case the above link goes down, here is the syntax:




SELECT distinguishedName, name
FROM OPENROWSET('ADSDSOObject', 'adsdatasource'
, 'SELECT distinguishedName, name, memberOf
FROM ''LDAP://microsoft.com/DC=microsoft,DC=com''
WHERE objectClass = ''user''
'
)



The final link on that page:

http://msdn.microsoft.com/library/de...ce_mapping.asp

indicates that these are all valid field names:


givenname
sn
initials
displayname
description
mail

userprincipalname
samaccountname

memberof
primarygroupid

profilepath
scriptpath

department
company
manager



There are a couple more on that particular link.


You may have to use a process of elimination if some of them won't return.
0
 
LVL 29

Author Comment

by:QPR
ID: 16982410
thanks, stupidly I wasn't reading correctly and was trying to select fields from the outer select that weren't "selected in the inner if you get my drift. The network admin has shown me the AD schema so I now know which columns to selct.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

690 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