Search code examples
sql-serverldaplinked-serverldap-query

Can I do an UPDATE using a linked active directory server?


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?


Solution

  • 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:

    Active Directory searches using ADO are very efficient. The provider retrieves records matching your query criteria in one operation, without the need to bind to many objects. However, the resulting recordset is read-only, so ADO cannot be used to modify Active Directory objects directly. If you need to modify attribute values, you will have to bind to the object.