sqlserver 2017 error 7321, Level 16, State 2, Line 1

Hasan Mosharrof 0 Reputation points
2023-03-14T09:58:13.5233333+00:00

Our Active Directory Linked Server name is LDAP
I am trying to run the following query

SELECT top 100 * FROM OPENQUERY 
(LDAP, ' SELECT * FROM
''LDAP://DC=****,DC=company,DC=****,DC=de''
WHERE objectClass = ''User'' ') ad

getting the following error though LDAP test connection shows successful and

Security Settings: Be made using the login's current security context

Msg 7321, Level 16, State 2, Line 1

SELECT
    *
FROM
'LDAP://DC=****,DC=company,DC=****,DC=de'
WHERE 
    objectClass = 'User'
" for execution against OLE DB provider "ADsDSOObject" for linked server "LDAP". 


Any guideline is much appreciated

Windows for business Windows Client for IT Pros Directory services Active Directory
SQL Server Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Seeya Xi-MSFT 16,586 Reputation points
    2023-03-15T03:01:08.9433333+00:00

    Hi @Hasan Mosharrof,

    You can use double quotes to enclose the LDAP path instead of single quotes. Then, you can use single quotes to enclose the value of the "objectClass" attribute.

    Best regards,

    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

  2. Hasan Mosharrof 0 Reputation points
    2023-03-17T14:18:09.8266667+00:00

    Somehow "Be use current security context" which is our AD account works for prod and doesn't works for test server
    In sp_addlinkedsrvlogin we changed @useself=True to False and explicitly used username and password and recreated the LDAP. Then bingo!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.