Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Querying AD

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

636 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