martes, 9 de marzo de 2010

Query Active Directory from SQL Server

If you need to access some Active Directory information from SQL Server you can use the openquery command with the ADSI provider, below is an example for doing that


select *

from openquery(adsi, '

select            displayName

from    ''LDAP://dc=comunidadwindows,dc=org''

where   objectCategory = ''Person''


        objectClass = ''user''

        and sAMAccountName = ''useraccountname''



You also must consider the segurity required inside Active Directory to allow the SQL Server Service account access to the corresponding OU, you can do it with Active Directory Users and Computers with Advance Features Enable and choosing the Security menu as show in the following figure:




You must give read access to the SQL Server Service Account.




Ing. Eduardo Castro Martínez, PhD – Microsoft SQL Server MVP

Costa Rica

Technorati Tags: SQL Server

LiveJournal Tags: SQL Server Tags: SQL Server

Note: Cross posted from Eduardo Castro.


No hay comentarios:

Publicar un comentario