本文介绍了从 SQL Server 2005 查询 Active Directory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 SQL Server 2005 查询 Active Directory?

How can I query Active Directory from SQL Server 2005?

推荐答案

很笼统的问题,但这里有一些提示.

Pretty general question but here are some pointers.

您需要在 SQL Server 上创建一个指向 ADSI(Active Directory 服务接口)的链接服务器,这样就可以了.

You need a linked server creating on the SQL Server that points to ADSI (Active Directory Service Interface) something like this will do it.

EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource'

然后您可以使用以下类型的查询.

Then you can use the following sort of query.


SELECT *
FROM OPENQUERY(ADSI, 'SELECT sAMAccountName
FROM ''LDAP://DC=MyDC,DC=com,DC=uk''
WHERE objectCategory = ''Person''
AND objectClass = ''user'')

您需要适当地设置 LDAP://行(详细信息请咨询您的 AD 管理员),并注意 SQL Server 中默认禁用使用 OpenQuery 的分布式即席查询.一旦你有了上述内容,谷歌搜索任何特定的变化应该很容易.

You'll need to set the LDAP:// line appropriately (ask your AD admin for the details) and be aware that distributed adhoc queries using OpenQuery are disabled by default in SQL Server. Once you have the above though it should be pretty easy to google for any particular variations.

这篇关于从 SQL Server 2005 查询 Active Directory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 14:33