views:

91

answers:

4

This might be a basic question, but I tried googling it and couldn't find an answer.

I need to make a list of all the SQL Servers on a network. This is very easy to do using the .NET framework (System.Data.Sql.SqlDataSourceEnumerator), but is there also a relatively simple way to do this in java as well? While I was doing my research, I came across the possibility of listening in at different ports, but that seemed un-user friendly.

I've been told to use SQL Browser Service, but a) I couldn't find any information on how to call that from java, and b) does this service get automatically downloaded when you download SQL Server? Can I assume that every computer on the network I'm searching has access to this browser service? And if not, does that make a difference to my code?

Thank you all so much.

+1  A: 

You can call COM components from java (with suitably crafted IDL), so you could use DMO or SMO (depending on your SQL Server version)

Mitch Wheat
+2  A: 

You can use SQLBrowseConnect function from ODBC API.

wqw
A: 

I have found it pretty easy to find all SQL services (assuming appropriate level of perms) by enumerating the Windows services on servers using WMI. This "catches" different SQL Server suite- services like Reporting Services and Analysis Services that are not the relational engine, plus services that are not running at the moment. I use this for license auditing, via PowerShell. So, if that seems useful, it's a matter of how to call WMI from Java. This dude: http://www.vijaykandy.com/archives/121 made a list of some options.

onupdatecascade
+1  A: 

I ended up using the command line's osql -L command to list all the servers on the network.

chama