I can use OpenQuery
to query ADSI from SSMS:
SELECT *
FROM OpenQuery (
ADSI,
'SELECT displayName, telephoneNumber, mail
, sAMAccountName
, division
, brancheNumber
FROM ''LDAP://DC=mydomain,DC=com''
WHERE objectClass = ''Person''
AND objectCategory = ''User''
')
Now, I want to use this in SSRS, it works fine on local. However, it always show error like below after I deploy the report to sharepoint site:
An error has occurred during report processing. (rsProcessingAborted)
The execution failed for the shared data set 'DataSet1'. (rsDataSetExecutionError)
Query execution failed for dataset 'DataSet1'. (rsErrorExecutingCommand)
Cannot execute the query "SELECT displayName, telephoneNumber, mail , sAMAccountName , division , brancheNumber FROM 'LDAP://mydomain,DC=com' WHERE objectClass = 'Person' AND objectCategory = 'User' " against OLE DB provider "ADsDSOObject" for linked server "ADSI".
Could not figure out why. so I tried another approach: use a sql job to run the openquery and save the data in a table. However, no matter what I tried, never succeeded. Anyone did this before? This is the error (run as user is set as mydomain\admin, on ADSI, local login of this account is set as Impersonate, Be Made using this security context is selected and mydomain\admin set as remote login (and its password):
Executed as user: mydomain\admin. Access to the remote server is denied because the current security context is not trusted. [SQLSTATE 42000] (Error 15274). The step failed.
If I remove "Run As User" in sql job, the error is:
Executed as user: NT AUTHORITY\NETWORK SERVICE. 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. [SQLSTATE 42000] (Error 7399) An error occurred while preparing the query "SELECT sAMAccountName, mail, division, brancheNumber FROM 'LDAP://mydomain,DC=com' WHERE objectClass = 'Person' AND objectCategory = 'User' " for execution against OLE DB provider "ADsDSOObject" for linked server "ADSI". [SQLSTATE 42000] (Error 7321). The step failed.
The purpose of this is to query a field in the SQL using an attribute from AD for the user whoever run the query. Anyone has any suggestions to do this?
Thanks