I am trying to query Active Directory using Linked Server using the following code in SQL Server 2008:
--Creation of Linked Server
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5',
The above statement is successfully executed.
--Querying the Active Directory
select * from openquery(ADSI,'SELECT name, cn, givenName, description
WHERE objectCategory = ''Person'' AND objectClass = ''user''')
The error which I get when executing the above query is:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "ADSDSOObject" for linked server "ADSI" reported an error. The provider indicates that the user did not have the permission to perform the operation.
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT name, cn, givenName, description
WHERE objectCategory = 'Person' AND objectClass = 'user'" for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".
Please suggest me to resolve the above error.