Hi everyone,
how to retrieve programatically the list of the AD's Sql Servers?
You've been looking at SMO classes but it seems that it depends of your own workstation.
Thanks in advance
Hi,what about using the
SmoApplication.EnumAvailableSqlServers()
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||Your best bet is to do something like an LDAP query specifying the OU (Organizational Unit) the servers were defined with. The EnumAvailableServers method will scout the SQL Server browsers on your network and bring back everything that responds to a ping, whether the server was defined in AD or not. (Joe Developer may have SQL Server Dev Ed running on his laptop, and you're probably not interested in that server.) Here's a starting point for you:
Dim mySearcher As DirectorySearcher
Dim resEnt As SearchResult
Dim colResults As SearchResultCollection
'Note : microsoft is the name of my domain for testing purposes.
Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://yourdomain")
mySearcher = New DirectorySearcher(enTry)
mySearcher.Filter = ("(objectClass=*)")
colResults = mySearcher.FindAll
For Each resEnt In colResults
Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString())
Console.WriteLine(resEnt.GetDirectoryEntry().Path.ToString())
Console.WriteLine(resEnt.GetDirectoryEntry().NativeGuid.ToString())
Console.WriteLine("===========================================")
Next
|||
Thanks a lot to both. I'll check that tomorrow.
Happy coding!
No comments:
Post a Comment