SQL Server 2019 Error 7321 Querying Active Directory

HSB 65 Reputation points
2023-08-23T17:46:51.4333333+00:00

I get the following error: Msg 7321, Level 16, State 2, Line 14 when I run:

SELECT * FROM OPENQUERY(
	ADSI,
	'SELECT *
	FROM ''LDAP://MYDOMAIN.org/DC=MYDOMAIN,DC=org''
	WHERE objectClass = ''User''
	')

I'm using my login. I am an admin and can access Active Directory, change users etc. I have set it to impersonate me and I've also tried "Be made using this security context" and supplying my credentials.

Here's a screenshot of AD and where users are located under General Users. I've tried adding OU=xx xx in the query but that doesn't change the error. Any thoughts on using SQL Server to query LDAP successfully?

User's image

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

1 answer

Sort by: Most helpful
  1. PercyTang-MSFT 12,511 Reputation points Microsoft External Staff
    2023-08-24T06:05:12.6433333+00:00

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.