1

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.

5 Answers5

1

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)

K. Brian Kelley
  • 9,004
  • 31
  • 33
0

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

  • Thank you. The problem is that I'm working on a program in java. As far as I've been able to tell, the only way to enumerate the servers is through the command line, but only if sql server exists on that computer. –  Feb 18 '10 at 15:26
  • Hi, see this link this seems to do what you need in just tsql http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=491&lngWId=5 –  Feb 18 '10 at 15:40
0

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

David Parvin
  • 101
  • 1
0

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.

0

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.

doug_w
  • 236
  • 1
  • 4