x

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, 2010 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, 2010 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, 2010 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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x985
x8

asked: Sep 07, 2010 at 05:35 PM

Seen: 1445 times

Last Updated: Sep 07, 2010 at 05:35 PM