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

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,365 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,245 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Seeya Xi-MSFT 16,461 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!

    0 comments No comments