I'm trying to find a list of all sql servers on the network using the osql -L
command in the command prompt. This command only works when SQLServer is installed on the computer that I'm working on. Is there any way to run this command when SQLServer is not installed on that particular computer, but is installed somewhere on the network?
Thank you!
EDIT: I'm writing a program in java, so the easy enumerations that you can do in the .NET framework won't work for me.
If you're looking for a command-line program you can run and get the input back from, look at SQLPing3 Command Line. I know it says it's in alpha but it works fine. It'll use all known methods to discover a SQL Server, which goes beyond osql -L (which simply does a udp/1434 broadcast).
SQLPing3 Command Line (and other free tools from SQLSecurity.com)
look at this link
http://www.sqldbatips.com/showarticle.asp?ID=45
This link shows how to do it by code via .Net framework if you are looking for way with some other programing language or platform please say
According to the documentation of the utility, it should show both the local servers as well as the ones on the network. The issue could be that the SQL Browser service is not running and that service is what is used to get a list of all the SQL Servers on a network.
SQL Browser Service: http://msdn.microsoft.com/en-us/library/ms181087.aspx
You can download SQLCMD separately from microsofts website:
Microsoft SQL Server 2005 Command Line Query Utility
Replace your call to osql with sqlcmd. The command line arguments and outputs are the same for your purposes.
Before relying on the SMO objects to return you the list of available SQL Instances on the network you should read this about the SqlDataSourceEnumerator. It can return incomplete or inconsistent results.