I am trying to use ADSI to query our domain's Active Directory. I used ADSI successfully to query the Exchange directory when we were on Exchange 5.5 but now that we are migrating to Exchange 2000 I need to query the Active Directory for the information I need.
After running the following code to set up the linked server:
I run this code to query the directory:
I have tried the same LDAP search using the same logon and password in a standalone LDAP query program and got the results I expected, so I do not believe that there is truly a permissions issue. Is there any limitation to the ADSI Services provider with spaces in the user name, or is my syntax incorrect somewhere, or is there some other problem I haven't thought of?
I have searched extensively in the Microsoft knowledge base but information on ADSI is hard to find, and often the information you find has more to do with VB than SQL Server. Any help you can give would be appreciated.
After running the following code to set up the linked server:
Code:
sp_addlinkedserver 'ActiveDirectory', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'
GO
sp_addlinkedsrvlogin 'ActiveDirectory', 'false', NULL, 'CN=IntranetServer,OU=Non-Employee User Accounts,DC=cha-llp,DC=com', 'mypassword'
GO
Code:
SELECT sAMAccountName, sn, givenName, LOWER(mail) AS mail
FROM openquery(ADSI,'<LDAP://cha-llp.com:389/DC=cha-llp,DC=com>;(sAMAccountName=*);sAMAccountName,sn,givenName,mail;subtree')
where sn is not null
order by sAMAccountName
[code]
But I get this error:
[code]
Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'ADSDSOObject' reported an error. The provider indicates that the user did not have the permission to perform the operation.
OLE DB error trace [OLE/DB Provider 'ADSDSOObject' ICommandPrepare::Prepare returned 0x80040e09: The provider indicates that the user did not have the permission to perform the operation.].
I have searched extensively in the Microsoft knowledge base but information on ADSI is hard to find, and often the information you find has more to do with VB than SQL Server. Any help you can give would be appreciated.