如何从 Java 查询 SQL Browser 服务?
这可能是一个基本问题,但我尝试用谷歌搜索但找不到答案。
我需要列出网络上所有 SQL Server 的列表。使用.NET框架(System.Data.Sql.SqlDataSourceEnumerator)可以很容易地做到这一点,但是在java中是否也有一种相对简单的方法来做到这一点?当我进行研究时,我发现了在不同端口监听的可能性,但这似乎对用户不友好。
我被告知要使用 SQL 浏览器服务,但是 a) 我找不到任何有关如何从 java 调用该服务的信息,b) 下载 SQL Server 时是否会自动下载该服务?我是否可以假设我正在搜索的网络上的每台计算机都可以访问此浏览器服务?如果不是,这会对我的代码产生影响吗?
非常感谢大家。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用来自 ODBC API 的 SQLBrowseConnect 函数。
You can use SQLBrowseConnect function from ODBC API.
您可以从 java 调用 COM 组件(使用适当设计的 IDL),因此您可以使用 DMO 或 SMO(取决于您的 SQL Server 版本)
You can call COM components from java (with suitably crafted IDL), so you could use DMO or SMO (depending on your SQL Server version)
我最终使用命令行的
osql -L
命令列出网络上的所有服务器。I ended up using the command line's
osql -L
command to list all the servers on the network.我发现通过使用 WMI 枚举服务器上的 Windows 服务,可以很容易地找到所有 SQL 服务(假设权限级别适当)。这会“捕获”不同的 SQL Server 套件 - 诸如 Reporting Services 和 Analysis Services 之类的非关系引擎服务,以及当前未运行的服务。我通过 PowerShell 使用它进行许可证审核。因此,如果这看起来有用,那么问题就在于如何从 Java 调用 WMI。这家伙:http://www.vijaykandy.com/archives/121 列出了一些选项。
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.