I linked my SQL Server 2008 to Active Directory like this:
EXEC sp_addlinkedserver
'ADSI',
'Active Directory Services 2.5',
'ADSDSOObject',
'adsdatasource'
Then I can query my phone number like this:
SELECT *
FROM OPENQUERY(
ADSI,
'SELECT DisplayName, TelephoneNumber from ''LDAP://ad1/DC=directagents,DC=local'' WHERE DisplayName=''Aaron Anodide''')
where not DisplayName is null
order by DisplayName
But I have not been able to change my phone number, as this causes an error:
SELECT * FROM
OPENQUERY(
ADSI,
'UPDATE TelephoneNumber from ''LDAP://ad1/DC=directagents,DC=local'' SET TelephoneNumber=''136'' WHERE DisplayName=''Aaron Anodide''')
Error:
Msg 7321, Level 16, State 2, Line 2
An error occurred while preparing the query…
Is this possible or is the idea that this is used for read-only access?
As far as I know, the SQL Server-to-Active Directory interface is read-only – you can select from AD, but you cannot update it.
See Richard Mueller’s ADO Search Tips on the topic – he states: