SQL Server 查询 Active Directory
来源:互联网 发布:网络io 文件系统 编辑:程序博客网 时间:2024/06/05 04:40
原文链接:http://jimshu.blog.51cto.com/3171847/1114364/
通过ADSI(Active Directory Service Interface)和LDAP可以查询Windows 2000的Active Directory。每次查询最多可以返回1000条记录。
一、启用 'Ad Hoc Distributed Queries'
在SQL Server执行以下查询:
sp_configure 'show advanced options',1
go
reconfigure with override
go
sp_configure 'Ad Hoc Distributed Queries',1
go
reconfigure with override
go
说明:如果未启用即席分布式查询,在下一步执行查询时会报错。
消息 15281,级别 16,状态 1,第 1 行
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
二、OPENROWSET
1、执行查询
select * from
openrowset('ADSDSOObject','adsdatasource',
' select Name,displayName,SAMAccountName from
"LDAP://DC1.contoso.com/ou=Shenzhen,ou=South,dc=contoso,dc=com" ')
2、添加权限
如果权限不够,会出现以下错误。
消息 7321,级别 16,状态 2,第 1 行
准备对链接服务器 "(null)" 的 OLE DB 访问接口 "ADSDSOObject" 执行查询" select Name,displayName,SAMAccountName from
"LDAP://contoso.com/ou=Shenzhen,ou=South,dc=contoso,dc=com" "时出错。
可以在查询时添加登录帐户信息:
select * from
openrowset('ADSDSOObject','adsdatasource';'contoso\administrator';'password',
' select Name,displayName,SAMAccountName from
"LDAP://DC1.contoso.com/ou=Shenzhen,ou=South,dc=contoso,dc=com" ')
三、OPENQUERY
1、创建链接服务器
执行以下查询:
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5',
'ADSDSOObject', 'adsdatasource'
GO
结果如下:
2、执行查询
select * from
openquery(ADSI,
' select Name,displayName,SAMAccountName from
"LDAP://DC1.contoso.com/ou=Shenzhen,ou=South,dc=contoso,dc=com" ')
3、添加权限
如果在查询时由于权限不够而报错,可按以下方式添加。
=================================================================================================================================
按照上面的说明试了试,发现 【添加权限】的时候还是出现上文提到的错误,然后,将下面代码执行的一次
CREATE VIEW temp
as
SELECT [NAME], ADsPath [DN], Company [comp]
FROM OPENQUERY( ADSI,
'SELECT Name, ADsPath, COMPANY
FROM ''LDAP://servername/ DC=AAAAAA,DC=com''
WHERE objectCategory = ''Person'' AND
objectClass = ''user''')
GO
Drop table test.dbo.ADDATA
GO
Select *
into test.dbo.ADDATA
from temp
GO
EXEC sp_dropserver 'ADSI'
GO
Drop view temp
虽然也有错误但是,但是在执行如上语句的时候,竟然可以了,完全可以查询到LDAP里面的用户信息。
不知道为啥。
- SQL Server 查询 Active Directory
- 查询Active Directory(LDAP)
- Deployment Server / Active Directory Synchronization
- Windows server 2008 -- Active Directory
- Jasper Server Active Directory Integration
- AD (Active Directory) 查询 权限管理
- 创建Windows 2000 Active Directory Server
- 创建Windows 2000 Active Directory Server
- Windows .NET Server 2003 Domains & Active Directory
- Windows .NET Server 2003 Domains & Active Directory
- MCTS Windows Server 2008 Active Directory Configuration
- Mastering Active Directory for Windows Server 2008
- windows server 2012 Active Directory 安装
- Active Directory
- Active Directory
- Active Directory
- Active Directory Rights Management Services (AD RMS) 无法查询 Active Directory 网域服务 (AD DS)
- 使用NET类和 LDAP 查询 Active Directory
- HDU 1232 并查集
- hdu 2952 Counting Sheep (dfs)
- centos将用户添加到sudo用户组的方法
- 数据结构之树的名称解析
- Linux ubuntu mint 系统安装和基本开发环境的搭建
- SQL Server 查询 Active Directory
- css&div学习笔记(2)
- C++基础知识面试笔试准备
- 网页报错有哪些错误?比如说400错误、500错误、404错误
- java中ftp断点上传功能的实现
- volley 应用 GET POST请求 图片异步加载(全面)
- drawable-hdpi,drawable-ldpi,drawable-mdpi区别?
- Matlab在训练神经网络时突然停止 Validation Stop
- Scala环境搭建之eclipse