SQLServer 通过使用 ADSI 执行分布式查询ActiveDorectory对象
2010-05-22 09:45
621 查看
Step 1:Creating a Linked Server.
对于 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.
引用:
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
[/code]
以上方法源自于:http://www.sqlservercentral.com/Forums/Topic231658-54-1.aspx#bm231954
我推荐的方法:在微软搜索到的.如何通过 NTDSUtil为服务器修改限制 maxPageSize
Modifying policy settings
资料来源:
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
EXEC sp_addlinkedsrvlogin @rmtsrvname = N'ADSI', @locallogin = NULL , @useself = N'False', @rmtuser = N'domain\Account', @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
[/code]
以上方法源自于: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. |
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 使用ADSI执行分布式查询ActiveDorectory对象
- SQLServer 使用ADSI执行分布式查询ActiveDorectory对象
- 关于:“无法序列化会话状态。在“StateServer”或“SQLServer”模式下,ASP.NET 将序列化会话状态对象,因此不允许使用无法序列化的对象或 MarshalByRef 对象。如果自定义会话状态存储在“Custom”模式下执行了类似的序列化,则适用同样的限制。”的问题
- C#中的类SqlCommand对象使用方法ExecuteNonQuery()调用SQLServer存储过程时,存储过程执行成功,数据发生改变,但是返回-1
- 无法序列化会话状态。在“StateServer”或“SQLServer”模式下,ASP.NET 将序列化会话状态对象,因此不允许使用无法序列化的对象或 MarshalByRef 对象。如果自定义会话状态存储在“Custom”模式下执行了类似的序列化,则适用同样的限制。
- 无法序列化会话状态。在“StateServer”或“SQLServer”模式下,ASP.NET 将序列化会话状态对象,因此不允许使用无法序列化的对象或 MarshalByRef 对象。如果自定义会话状态存储在“Custom”模式下执行了类似的序
- 关于:“无法序列化会话状态。在“StateServer”或“SQLServer”模式下,ASP.NET 将序列化会话状态对象,因此不允许使用无法序列化的对象或 MarshalByRef 对象。如果自定义会话状态存储在“Custom”模式下执行了类似的序列化
- sqlserver 中使用sqlcmd 执行几百M的.sql文件
- linux c之通过popen和pclose函数创建管道执行shell 运行命令使用总结
- 简单使用JSON,通过JSON 字符串来创建对象(二)
- 通过class类来实例化其他类的对象(使用有参构造函数)
- Js使用WScript.Shell对象执行.bat文件和cmd命令
- 黑马程序员之ADO.NET学习笔记:通过SqlCommand对象执行SQL语句
- 使用代码创建的控件对象,设置的事件监听方法不执行的问题
- 通过jQuery Ajax使用FormData对象上传文件
- 通过jQuery Ajax使用FormData对象上传文件
- 使用SQLCMD在SQLServer执行多个脚本
- 通过jQuery Ajax使用FormData对象上传文件
- 通过jQuery Ajax使用FormData对象上传文件
- 通过jQuery Ajax使用FormData对象上传文件