TSQL: access user data from LDAP
<p>I have an Active Directory (LDAP) that stores user information. I'm trying to access it using TSQL, but I'm having authentication problems.</p>

<p>The LDAP looks like this (I edited the data): </p>

<p><a href="https://i.stack.imgur.com/4TLUt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4TLUt.png" alt="enter image description here"></a></p>

<p>The user has the following properties:</p>

<p><a href="https://i.stack.imgur.com/Op5fg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Op5fg.png" alt="enter image description here"></a></p>

<p>Now, I'm trying to get the info from this user through a TSQL query from SQL Server using OPENROWSET like so:</p>

<pre><code>SELECT *
FROM 
OPENROWSET('ADSDSOObject','adsdatasource'; 'domain.com.io\test';'the_sha1_pass',
'SELECT  givenname
    FROM ''LDAP://domain.com.io/ou=Users,
      dc=domain,dc=com,dc=io'' WHERE givenname = ''Test''
      ')
</code></pre>

<p>But when I execute it I get the following error:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>Now, I don't know if I have to send the authentication of the user I'm trying to query over, or the credentials I use to connect with LDAPAdmin. And if I have to send it, should I send the pass already encrypted or without encryption?</p>

<p>Thanks.</p>