x
login about faq Site discussion (meta-askssc)

How to dinamically query the first available Active Directory Servers

Hi everybody,

I use this code to query Active Directory, with the AD server name hardcoded:

SET @PCdis=(SELECT COUNT(*) FROM OPENQUERY(ADSI,'SELECT Name,distinguishedName FROM ''LDAP://MY_AD_SERVER/OU=XX,OU=Domain Computers,DC=XXX,DC=XXX,DC=XX'' WHERE objectCategory = ''computer'' AND userAccountControl= 4130'));

Recently, my Active Directory server went off-line and I have to change the code of the query to point another AD Server in the forest, my question is:

Is there any way to dinamically query the most-available AD server for querys instead of coding the server name..?

Best regards,

JD

more ▼

asked May 05 '12 at 01:28 PM in Default

JD gravatar image

JD
104 3 6 7

(comments are locked)
10|1200 characters needed characters left

1 answer: sort oldest

If you can drop out to a command prompt or query the registry you can find a value from the system environment variable LOGONSERVER. This usually requires a logged on user to populate though.

An alternative is to PING the domain name for an IP.

more ▼

answered May 07 '12 at 12:33 PM

Blackhawk-17 gravatar image

Blackhawk-17
10.5k 23 29 34

Hi, thanks for the tip.!

It won't work if the server in the LOGONSERVER variable went down after login...!

May 07 '12 at 11:24 PM JD
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x92
x26
x6

asked: May 05 '12 at 01:28 PM

Seen: 441 times

Last Updated: May 07 '12 at 11:25 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.