x
login about faq Site discussion (meta-askssc)

Error when Selecting AD attribute with a hyphen in the name

Good morning again all

I have a problem accessing an attribute in AD via an LDAP open Query. The attribute has a hyphen inthe name and I get various errors depending on how I treat it: eg. SELECT 'OU=IT,OU=People' as OU ,sAMAccountName ,distinguishedName ,PhoneticDisplayName FROM OpenQuery(ADSI,'SELECT sAMAccountName ,distinguishedName ,[msDS-PhoneticDisplayName] as PhoneticDisplayName FROM''LDAP://OU=IT,OU=USERS2008,OU=ACCOUNTS,DC=x,DC=y,DC=z'' WHERE objectCategory=''Person'' and objectClass = ''user'' ' )

returns Msg 7321, Level 16, State 2, Line 2 An error occurred while preparing the query "SELECT sAMAccountName ...... for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".

Without the square brackets, it searches for an sttribute name msDS. With the square brackets I get the above error. Does anyone have any ideas on how I can around this?

Thanks.

more ▼

asked Sep 07 '10 at 05:35 PM in Default

Fizz gravatar image

Fizz
56 8 8 8

Hi all I have solved it. No idea how but by cutting various segments and running them separately then patching it back together it now runs.

Sep 07 '10 at 10:48 PM Fizz
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Hi all I have solved it. No idea how but by cutting various segments and running them separately then patching it back together it now runs.

more ▼

answered Sep 07 '10 at 10:49 PM

Fizz gravatar image

Fizz
56 8 8 8

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x916
x6

asked: Sep 07 '10 at 05:35 PM

Seen: 860 times

Last Updated: Sep 07 '10 at 05:35 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.