Msg 7321, Level 16, State 2, Line 68
An error occurred while preparing the query "
Solution:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/083229e7-58f2-44cf-ae5d-c9acf366818c/sql-2005-ldap-query-error-msg-7321-level-16?forum=transactsql
It normally succeedes test connection generally but when you run query using this linked server to pull data from AD(Active Directory) server it will throw above issue. so issue will be between db server of linked server and AD server.
we need to make sure logins should be same on both AD server and db server
of linked server created.
LDAP means Lightweight Directory Access Protocol
First execute your query:
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces',
'ADSDSOObject'
, 'adsdatasource'
GO
Like daw21 explain before follow the detail steps:
Second step go to the SqlServer management Studio and edit manually the Linkserver name ADSI:
go to Server Objects/Linked Servers/ and right click on ADSI select the option Properties and then go to Security.
Select the option : Be made using this security context:
and there fill the user and Password about the valid user with permission into Active Directory, not forget before the domain\user.
(or)
First you have to make sure that Ad Hoc Distributed Queries is enabled ...
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
Second you have to make sure that you specify a security context that has access to AD INCLUDING the DOMAIN
Third you should put a row limit (e.g. SELECT TOP 100) in to avoid the issue where you hit the 1000 row limit so
SELECT
TOP 100 *
FROM
OpenQuery(ADSI, 'SELECT sAMAccountName FROM ''LDAP://DC=core,DC=acllab,DC=net'' WHERE objectCategory=''user'' ')
An error occurred while preparing the query "
Solution:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/083229e7-58f2-44cf-ae5d-c9acf366818c/sql-2005-ldap-query-error-msg-7321-level-16?forum=transactsql
It normally succeedes test connection generally but when you run query using this linked server to pull data from AD(Active Directory) server it will throw above issue. so issue will be between db server of linked server and AD server.
we need to make sure logins should be same on both AD server and db server
of linked server created.
LDAP means Lightweight Directory Access Protocol
First execute your query:
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces',
'ADSDSOObject'
, 'adsdatasource'
GO
Like daw21 explain before follow the detail steps:
Second step go to the SqlServer management Studio and edit manually the Linkserver name ADSI:
go to Server Objects/Linked Servers/ and right click on ADSI select the option Properties and then go to Security.
Select the option : Be made using this security context:
and there fill the user and Password about the valid user with permission into Active Directory, not forget before the domain\user.
(or)
First you have to make sure that Ad Hoc Distributed Queries is enabled ...
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
Second you have to make sure that you specify a security context that has access to AD INCLUDING the DOMAIN
Third you should put a row limit (e.g. SELECT TOP 100) in to avoid the issue where you hit the 1000 row limit so
SELECT
TOP 100 *
FROM
OpenQuery(ADSI, 'SELECT sAMAccountName FROM ''LDAP://DC=core,DC=acllab,DC=net'' WHERE objectCategory=''user'' ')