Insert into Active Directory Using SQL

Micah Holmes 121 Reputation points

I have a User Account that's created using our ERP. Once created the SQL does some stuff to the record and spits out some attributes that later get updated in AD using a Batch job. I want to update the AD records in SQL and avoid he batch job all together to further optimize. Alternative is to build an API and perform the AD update in there using .Net code. However, it makes more sense to us to just update AD in SQL since SQL will already have the attribute data for the record we need to inject. So far not been able to find anything on how to write to AD from SQL. We already can read from AD to SQL. So there must be a way to write to AD from SQL. I assume we just need a connection or something? Anyone have samples or video tuts etc? Thanks

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,067 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,060 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 103.5K Reputation points MVP

    Nope. If you look at the documentation for the OLE DB provider for Active Directory at, you will find that it does not support write operations.

    Well, if you are going to do in .NET, you could do that from a CLR procedure, but if you are not using the CLR already, I am not sure that it is worth the complexity.

    0 comments No comments

  2. AmeliaGu-MSFT 13,961 Reputation points Microsoft Vendor

    Hi MicahHolmes-1650,

    Agree with Erland. You can use CLR stored procedure or CLR function with Directory Services object to update the Active Directory.
    Please refer to the following threads which might help:
    Update users in Active Directory form SQL query update
    Syncing Active Directory with my Application
    How to register System.DirectoryServices for use in SQL CLR User Functions

    Best Regards,

    0 comments No comments