Showing posts with label smo. Show all posts
Showing posts with label smo. Show all posts

Monday, March 19, 2012

Active Directory Sql Servers

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!

Sunday, February 19, 2012

Accessing the Log File Physical File Name and Path

I am new to SMO and VB.NET and I need to access the transaction log's physical file name and path so that I can correctly relocate it when it is restored on a different.

What I would like to do is display the database and log's physical file and path names in some type of data control for selection by a user during a restore operation.

I have been able to do this for the database but can't seem to get it to work for the log file. How do I find the log file's physical file name and path using SMO? I can't seem to be able to relate the logfile collection and class to specific databases.

Thanks for your help!

Database.LogFiles property gives you a collection of LogFile object, each of which represents a log file on the database. You can access the location and name of the log file using LogFile.FileName and LogFile.Name properties respectively. Refer BOL for more details.

Thanks,
Kuntal

|||Thanks, I've got it working now. I don't know what it was, but something you said sent me in the right direction. I already knew about Database.Logfiles but couldn't put it together until I read your post.