Fix: Msg 7321, Level 16, State 2, Line 1 An error occurred while preparing a query for execution against OLE DB provider ‘ADsDSOObject’. OLE DB error trace [OLE/DB Provider ‘ADsDSOObject’ ICommandPrepare::Prepare returned 0x80040e14].

Whenever you get the issue “Msg 7321” make sure your security context is correctly supplied. Otherwise you will get below error.

Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing a query for execution against OLE DB provider 'ADsDSOObject'. OLE DB error trace [OLE/DB Provider 'ADsDSOObject' ICommandPrepare::Prepare returned 0x80040e14].

We should use domain user account in sp_addlinkedserver stored procedure that has access rights to Active Directory. The domain name is required in the Security settings for the remote login. So in the Security settings I entered Remote login as domain user with password. Find below dummy example.

Step1: Run below command.

EXEC sp_addlinkedserver @server = N'ADSI', @srvproduct=N'Active Directory Services', @provider=N'ADsDSOObject', @datasrc=N'LINLDP2'

Output: Success

Step2: Execute below command now.

EXEC sp_addlinkedsrvlogin @rmtsrvname ='ADSI', @useself='false', @rmtuser='DomainNameUserName', @rmtpassword='#Security@SWIM#'

Also, Make sure your SQL Server Service is running under the account which has appropriate access.

Related Articles:

If you like this tip, you can follow us on our facebook page and on Twitter handle to get latest updates.

Manvendra Deo Singh
Follow me:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *