SQL 2005 LDAP Query Error: Msg 7321, Level 16

Hello I am trying to run a query via tsql against ad. Below is the error I am getting. I have read the http://msdn2.microsoft.com/en-US/library/ms190803.aspx and changed the domain but still having issues. Any help would be appreciated.

 

EXEC sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces',

'ADSDSOObject', 'adsdatasource'

GO

SELECT *

FROM OPENQUERY( ADSI,

'SELECT Name, SN, ST

FROM ''LDAP://ADSISrv/ OU=Users,DC=XXXXX,DC=LOCAL''

WHERE objectCategory = ''Person'' AND

objectClass = ''user''')

Msg 7321, Level 16, State 2, Line 1

An error occurred while preparing the query "SELECT Name, SN, ST

FROM 'LDAP://ADSISrv/ OU=Users,DC=XXXXX,DC=LOCAL'

WHERE objectCategory = 'Person' AND

objectClass = 'user'" for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".



Answer this question

SQL 2005 LDAP Query Error: Msg 7321, Level 16

  • marrigre

    The domain name is required in the Security settings for the remote login - I should have known that. So in the Security settings I selected Be made using this security context, entered Remote login: domain\user; With password: password.


  • SkiesOfBordom

    I got it to work on the local database server. It didn't seem to like the OU. Once I removed it the query completed. However I still get the message if I try and run the view from a remote computer using Mgmt Studio is there something I have to setup on the clients

    SELECT * FROM vcnet.dbo.viewADContacts--gives errors from workstations but not if run from the server itself

    Server: Msg 7321, Level 16, State 2, Line 1
    An error occurred while preparing the query "SELECT sAMAccountname,givenname,sn,displayname,useraccountcontrol,CN, manager, mobile , mail, objectCategory,
    department,
    telephoneNumber,
    facsimileTelephoneNumber
    FROM 'LDAP://DC=XXXXX,DC=local'
    WHERE objectCategory='person' AND objectClass='user'" for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".


  • jermaine88

    I'm having the same issue - query runs in management studio, but not elsewhere. Any idea why
  • JFoushee

    Check if the linked server (ADSI) allow remote accessing.
  • thedewd

    Did you ever get a resolution to this I am now having the same issue - query runs fine on the local SQL2k5 server but not on a remote server running Visual Dev.
  • SQL 2005 LDAP Query Error: Msg 7321, Level 16