从sql server 2005查询AD

发布于 2024-07-11 20:24:13 字数 621 浏览 6 评论 0原文

我尝试从 SQL Server 2005 中通过 ldap 查询 AD,但收到以下错误:

Msg 7321,Level 16,State 2,Line 1 准备查询“SELECT NAME,MAIL FROM “LDAP:///CN=foo,CN=Users,DC=bar,DC=com””以针对链接服务器“ADSI”的 OLE DB 提供程序“ADsDSOObject”执行时发生错误”。

这是执行以下存储过程之后的结果:
exec sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADsDSOObject', 'adsdatasource'

目前我正在本地 SQL Server 2005 实例上运行查询。 我尝试将安全上下文更改为 1) Made Without... 、2) made using the login's current... 和 3) Be made using this security context:指定我自己的域帐户。 这三个都出现同样的错误。

不确定这是否重要,但“bar”(请参阅​​上面的 ldap 查询)不是我的计算机(本地 sql 服务器实例)或 ldap 服务器的域。

有任何想法吗?

I am attempting to query AD via ldap from within SQL Server 2005 but get the following error:

Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT NAME,MAIL FROM "LDAP:///CN=foo,CN=Users,DC=bar,DC=com"" for execution against OLE DB provider "ADsDSOObject" for linked server "ADSI".

This is after executing the following stored proc:
exec sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADsDSOObject', 'adsdatasource'

Currently I'm running the query on my local SQL Server 2005 instance. I've tried changing the security context to 1) Made Without... , 2) made using the login's current..., and 3) Be made using this security context: specifying my own domain account. Same error with all three.

Not sure if it matters, but "bar" (see ldap query above) is not the domain of either my machine (local sql server instance) or the ldap server.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽梦紫曦~ 2024-07-18 20:24:13

主要问题是 LDAP 查询周围的双引号需要加倍单引号。

LDAP 查询可以包括服务器名称或 IP 和/或 LDAP 规范。

对我有用的查询:

SELECT * FROM OPENQUERY
(ADSI,'SELECT NAME FROM ''LDAP://*ldap.server.name*''')

一些

SELECT * FROM OPENQUERY
(ADSI, 'SELECT name, sAMAccountName, distinguishedName 
FROM ''LDAP://DC=*mycompany*, DC=*mytld*''
WHERE objectCategory = ''Person'' AND objectClass = ''user''')

 

SELECT * FROM OPENQUERY
(ADSI,'SELECT name, sAMAccountName, distinguishedName
FROM ''LDAP://*ldap.server.name*/OU=ITDept, OU=users, OU=DC, OU=Corporate, DC=*mycompany*, DC=*mytld*''
WHERE objectCategory = ''Person'' AND objectClass = ''user''')

再次...上面没有双引号...多个单引号。

ADSI 需要注册/链接,

EXEC sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'

如果您有权限问题,您可以在 ADSI 链接服务器上的安全属性选项卡下设置使用的帐户。

The main problem is that the double quotes around the LDAP query need to be doubled single quotes.

The LDAP query can include as server name or IP and/or a LDAP specification.

Some queries that work for me:

SELECT * FROM OPENQUERY
(ADSI,'SELECT NAME FROM ''LDAP://*ldap.server.name*''')

SELECT * FROM OPENQUERY
(ADSI, 'SELECT name, sAMAccountName, distinguishedName 
FROM ''LDAP://DC=*mycompany*, DC=*mytld*''
WHERE objectCategory = ''Person'' AND objectClass = ''user''')

SELECT * FROM OPENQUERY
(ADSI,'SELECT name, sAMAccountName, distinguishedName
FROM ''LDAP://*ldap.server.name*/OU=ITDept, OU=users, OU=DC, OU=Corporate, DC=*mycompany*, DC=*mytld*''
WHERE objectCategory = ''Person'' AND objectClass = ''user''')

Once again... there are no double quotes in the above... multiple single quotes.

ADSI needs to be registered/linked with

EXEC sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'

if you have permissions issues you can set the account used under the security property tab on the ADSI linked server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文