?
Solved

Querying AD

Posted on 2006-06-25
5
Medium Priority
?
215 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

752 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