How do I query SQL Browser Service from Java?
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 differ开发者_JAVA技巧ent 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.
You can use SQLBrowseConnect function from ODBC API.
You can call COM components from java (with suitably crafted IDL), so you could use DMO or SMO (depending on your SQL Server version)
I ended up using the command line's osql -L
command to list all the servers on the network.
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.
精彩评论