当前位置:  数据库>sqlserver

SQLServer 使用ADSI执行分布式查询ActiveDorectory对象

    来源: 互联网  发布时间:2014-09-05

    本文导语:  Step 1:Creating a Linked Server. EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource' Step 2:Creating a SQL Server Authenticated Login EXEC sp_addlinkedsrvlogin @rmtsrvname = N'ADSI', @locallogin = NULL , @useself = N'False', @rmtuser = N'domainAcco...

Step 1:Creating a Linked Server.
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource'
Step 2:Creating a SQL Server Authenticated Login
EXEC sp_addlinkedsrvlogin @rmtsrvname = N'ADSI', @locallogin = NULL , @useself = N'False', @rmtuser = N'domainAccount', @rmtpassword = N'Password'
对于 SQL Server 授权登录,可以使用sp_addlinkedsrvlogin 系统存储过程配置用于连接到目录服务的适当的登录/密码.
参考这里: http://blogs.msdn.com/euanga/archive/2007/03/22/faq-how-do-i-query-active-directory-from-sql-server.aspx
如果SQLServer使用Windows 授权登录,只需自映射就足以通过使用 SQL Server 安全委托来访问AD。简单点说就是直接运行第三步语句即可.
Step 3:Querying the Directory Service.
代码如下:

-- Query for a list of User entries in an OU using the SQL query dialect
select convert(varchar(50), [Name]) as FullName,
convert(varchar(50), Title) as Title,
convert(varchar(50), TelephoneNumber) as PhoneNumber
from openquery(ADSI,
'select Name, Title, TelephoneNumber
from ''LDAP://OU=Directors,OU=Atlanta,OU=Intellinet,DC=vizability,DC=intellinet,DC=com''
where objectClass = ''User''')
-- Query for a list of Group entries in an OU using the SQL query dialect
select convert(varchar(50), [Name]) as GroupName,
convert(varchar(50), [Description]) GroupDescription
from openquery(ADSI,
'select Name, Description
from ''LDAP://OU=VizAbility Groups,DC=vizability,DC=intellinet,DC=com''
where objectClass = ''Group''')

引用:
http://msdn2.microsoft.com/en-us/library/aa772380.aspx
http://www.atlantamdf.com/presentations/AtlantaMDF_111201_examples.txt

说明:但是这样默认查询出来的是1000个对象.怎么办呢?
方法一,通过字母来循环.见以下:
代码如下:

CREATE TABLE #tmpADUsers
( employeeId varchar(10) NULL,
SAMAccountName varchar(255) NOT NULL,
email varchar(255) NULL)
GO
/**//* AD is limited to send 1000 records in one batch. In an ADO interface you can define this batch size, not in OPENQUERY.
Because of this limitation, we just loop through the alphabet.
*/
DECLARE @cmdstr varchar(255)
DECLARE @nAsciiValue smallint
DECLARE @sChar char(1)
SELECT @nAsciiValue = 65
WHILE @nAsciiValue < 91
BEGIN
SELECT @sChar= CHAR(@nAsciiValue)
EXEC master..xp_sprintf @cmdstr OUTPUT, 'SELECT employeeId, SAMAccountName, Mail FROM OPENQUERY( ADSI, ''SELECT Mail, SAMAccountName, employeeID FROM ''''LDAP://dc=central,dc=mydomain,dc=int''''WHERE objectCategory = ''''Person'''' AND SAMAccountName = ''''%s*'''''' )', @sChar
INSERT #tmpADUsers
EXEC( @cmdstr )
SELECT @nAsciiValue = @nAsciiValue + 1
END
DROP TABLE #tmpADUsers

以上方法源自于:http://www.sqlservercentral.com/Forums/Topic231658-54-1.aspx#bm231954

我推荐的方法:在微软搜索到的.如何通过 NTDSUtil为服务器修改限制 maxPageSize

1.

Click Start, and then click Run.

2.

In the Open text box, type ntdsutil, and then press ENTER. To view help at any time, type ? at the command prompt.

Modifying policy settings

1.

At the Ntdsutil.exe command prompt, type LDAP policies, and then press ENTER.

2.

At the LDAP policy command prompt, type Set setting to variable, and then press ENTER. For example, type Set MaxPoolThreads to 8.

This setting changes if you add another processor to your server.

3.

You can use the Show Values command to verify your changes.

To save the changes, use Commit Changes.

4.

When you finish, type q, and then press ENTER.

5.

To quit Ntdsutil.exe, at the command prompt, type q, and then press ENTER.

资料来源:

http://support.microsoft.com/kb/315071/en-us

http://support.microsoft.com/?scid=kb%3Bzh-cn%3B299410&x=16&y=10

如何使用SQL查询活动目录对象语法: http://www.microsoft.com/china/technet/community/columns/scripts/sg0505.mspx#EMBAC


    
 
 

您可能感兴趣的文章:

  • SQLSERVER分布式事务使用实例
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 连接sqlserver的url是jdbc:microsoft:sqlserver://192.168.0.100:1433,他连那一个数据库呢?
  • (100分)用Microsoft jdbc Driver for sqlserver2000(type4)访问sqlserver2k的问题,help!
  • 通过SQLSERVER重启SQLSERVER服务和计算机的方法
  • 怎样用文JDBC for sqlserver访问SQLSERVER 数据库请大侠给出一个完整的程序代码
  • (100分)jdbc连接sqlserver 200出错.[SQLServer 2000 Driver for JDBC]Error establishing socket.
  • 如何连接sqlserver2000数据库
  • 深入JDBC sqlserver连接写法的详解
  • how to 连接到sqlserver2000?
  • 请问如何直接sqlserver?
  • SQLServer JDBC Driver
  • 在sqlserver2000时中文问题。
  • 设置密码保护的SqlServer数据库备份文件与恢复文件的方法
  • 如何使用JSP 连接SQLSERVER数据库,请不吝赐教!(在线等,急救!)
  • 简单实现SQLServer转MYSQL的方法
  • 求助!SQLServer2000 JDBC Driver 不能加载?
  • Resin+Jsp+Sqlserver2000的问题!在线等候!
  • applet用jdbc链接SQLServer 2000的问题
  • 请问连接SQLServer 的驱动器是什么呢?
  • jdbc:microsoft:sqlserver://localhost:1433;DatabaseNameOPTIONAL=webmail???
  • 如何用SQLServer2k-JDBC连接数据库?


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3