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

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

1 answer

Sort by: Most helpful
  1. Anonymous
    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.