SQLServer 使用ADSI執(zhí)行分布式查詢ActiveDorectory對(duì)象
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'domain\Account', @rmtpassword = N'Password'
對(duì)于 SQL Server 授權(quán)登錄,可以使用sp_addlinkedsrvlogin 系統(tǒng)存儲(chǔ)過(guò)程配置用于連接到目錄服務(wù)的適當(dāng)?shù)牡卿?密碼.
參考這里: http://blogs.msdn.com/euanga/archive/2007/03/22/faq-how-do-i-query-active-directory-from-sql-server.aspx
如果SQLServer使用Windows 授權(quán)登錄,只需自映射就足以通過(guò)使用 SQL Server 安全委托來(lái)訪問(wèn)AD。簡(jiǎn)單點(diǎn)說(shuō)就是直接運(yùn)行第三步語(yǔ)句即可.
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
說(shuō)明:但是這樣默認(rèn)查詢出來(lái)的是1000個(gè)對(duì)象.怎么辦呢?
方法一,通過(guò)字母來(lái)循環(huán).見(jiàn)以下:
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
我推薦的方法:在微軟搜索到的.如何通過(guò) NTDSUtil為服務(wù)器修改限制 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. |
3. |
You can use the Show Values command to verify your 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. |
資料來(lái)源:
http://support.microsoft.com/kb/315071/en-us
http://support.microsoft.com/?scid=kb%3Bzh-cn%3B299410&x=16&y=10
如何使用SQL查詢活動(dòng)目錄對(duì)象語(yǔ)法: http://www.microsoft.com/china/technet/community/columns/scripts/sg0505.mspx#EMBAC
相關(guān)文章
SQL語(yǔ)句查詢數(shù)據(jù)庫(kù)中重復(fù)記錄的個(gè)數(shù)
一個(gè)sql語(yǔ)句:一個(gè)表test有四個(gè)字段id,a,b,c,如果表中的記錄有三個(gè)字段a,b,c都相等,則說(shuō)明這條記錄是相同的,求相同的記錄的個(gè)數(shù) 。2009-11-11SQL Server實(shí)現(xiàn)顯示每個(gè)類(lèi)別最新更新數(shù)據(jù)的方法
這篇文章主要介紹了SQL Server實(shí)現(xiàn)顯示每個(gè)類(lèi)別最新更新數(shù)據(jù)的方法,涉及SQL Server數(shù)據(jù)庫(kù)Select查詢操作使用技巧,需要的朋友可以參考下2017-03-03精妙的SQL和SQL SERVER 與ACCESS、EXCEL的數(shù)據(jù)導(dǎo)入導(dǎo)出轉(zhuǎn)換
sqlserver 與access,excel互相導(dǎo)入導(dǎo)出代碼2008-03-03sqlserver中根據(jù)字符分割字符串的最好的寫(xiě)法分享
因數(shù)據(jù)庫(kù)中保存的是以,號(hào)分隔的數(shù)據(jù),需要在界面上以表格的方式顯示出來(lái)。特想出以下方法2012-05-05關(guān)于PowerDesigner初體驗(yàn)的使用介紹
本篇文章小編將為大家介紹,關(guān)于PowerDesigner初體驗(yàn)的使用介紹,有需要的朋友可以參考一下2013-04-04sqlserver下Kill 所有連接到某一數(shù)據(jù)庫(kù)的連接
可以通過(guò)下面代碼Kill所有連接到某一數(shù)據(jù)庫(kù)的所有連接2010-05-05sql查詢結(jié)果列拼接成逗號(hào)分隔的字符串方法
SQL查詢時(shí)會(huì)經(jīng)常需要,把查詢的結(jié)果拼接成一個(gè)字符串。那么怎么直接把sql查詢結(jié)果列拼接成逗號(hào)分隔的字符串方法,下面就一起來(lái)了解一下2021-05-05SQL?Server日期時(shí)間和字符串之間的轉(zhuǎn)換方法實(shí)例
處理原始數(shù)據(jù)時(shí),您可能經(jīng)常會(huì)遇到存儲(chǔ)為文本的日期值,將這些值轉(zhuǎn)換為日期數(shù)據(jù)類(lèi)型非常重要,因?yàn)樵诜治鲞^(guò)程中日期可能更有價(jià)值,下面這篇文章主要給大家介紹了關(guān)于SQL?Server日期時(shí)間和字符串之間的轉(zhuǎn)換方法,需要的朋友可以參考下2023-06-06SQL Server中使用判斷語(yǔ)句(IF ELSE/CASE WHEN )案例
這篇文章主要介紹了SQL Server中使用判斷語(yǔ)句(IF ELSE/CASE WHEN )案例,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07