We always used C# to query Active Directory, recently we need to add a patch to some code and it would be easier for us to query Active Directory straight from SQL DB as then we won't need to make any change to our code base other then stored procedures.

I got no clue how it would be seen in world of best practices, would it be considered a bad design move?

  • 2
    Never did it but sounds like very bad design to me. On the other hand, we know nothing about the specific requirement. Could you elaborate on what you are trying to achieve? – marstato Oct 12 '17 at 11:00
  • If your application is C#, it is new enough where the authors should have known better. Do not do it this way. – TheCatWhisperer Oct 12 '17 at 17:27

You can add .net class libraries to MSSQL. This will allow you to do anything that you can program. And you can definitely make a .net class lib that can query Active Directory


However! The only reason I can think of doing this is that you completely lack an application layer to your software and are doing everything in stored procs.

This is considered bad practice for many reasons, but most of all because code running on your SQL box slows down its primary function of being a database and makes it an expensive bottleneck to your entire operation.

Edit: As you updated I've thought of a second reason:

You have implemented change control on your source code, which means that if you change the source code you have some red tape to go through, perhaps versioning, testing and deployment. However, you have not implemented the same controls on your database and can update stored procs or data without having to do these things.

This is also bad practice, as you should implement the same change control for your database as you have with the rest of your code.

| improve this answer | |

You can create a linked server using the provider "OLE DB Provider for Microsoft Directory Services".

An alternative syntax is to use the OPENROWSET construct which takes the provider as a parameter.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.