question

Fizz avatar image
Fizz asked

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.
t-sqlactive-directory
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fizz avatar image Fizz commented ·
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.
0 Likes 0 ·

1 Answer

·
Fizz avatar image
Fizz answered
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.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.