Take the 2-minute tour ×

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.

share|improve this question

migrated from stackoverflow.com Feb 19 '10 at 4:27

This question came from our site for professional and enthusiast programmers.

5 Answers 5

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)

share|improve this answer

look at this link
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

share|improve this answer
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. –  chama Feb 18 '10 at 15:26
Hi, see this link this seems to do what you need in just tsql planetsourcecode.com/vb/scripts/… –  IordanTanev Feb 18 '10 at 15:40

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

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

