从AD中读取用户的相关属性
代码:
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource'
EXEC sp_configure 'show advanced options', 1
reconfigure with override
EXEC sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
SELECT * FROM OpenQuery(ADSI, 'SELECT * FROM ''LDAP://DC=AAAAAAA,DC=com'' WHERE objectCategory=''user'' ')
报错:
消息 15028,级别 16,状态 1,过程 sp_MSaddserver_internal,第 89 行
服务器 'ADSI' 已存在。
配置选项 'show advanced options' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'Ad Hoc Distributed Queries' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
消息 7330,级别 16,状态 2,第 14 行
无法从链接服务器 "ADSI" 的 OLE DB 访问接口"ADSDSOObject"提取行。
本人菜,请高手指点下。
------最佳解决方案--------------------
链接服务器建的有问题,见
http://www.cnblogs.com/MyFavorite/archive/2007/10/25/937516.html
------其他解决方案--------------------
我也菜 学习
------其他解决方案--------------------
这么快?
------其他解决方案--------------------
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5',
'ADSDSOObject', 'adsdatasource'
GO
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
已解决,谢谢!
------其他解决方案--------------------
强大无比,我也通过楼上命令解决的,特地matk下~~~~
------其他解决方案--------------------
运行
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5',
'ADSDSOObject', 'adsdatasource'
GO
提示 ----
Msg 15028, Level 16, State 1, Procedure sp_addlinkedserver, Line 82
The server 'ADSI' already exists.
直接运行
SELECT * FROM OpenQuery(ADSI, 'SELECT * FROM ''LDAP://XXX.XXX/DC=XX,DC=XX,DC=XX'' WHERE objectCategory=''user'' ')
就提示
Msg 7399, Level 16, State 1, Line 1
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.
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT * FROM 'LDAP://XXX.XXX/DC=XX,DC=XX,DC=XX'' WHERE objectCategory='user' " for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".