我试图确定我已经安装的sql server/sql express的实例(手动或编程),但所有的例子都告诉我运行一个sql查询来确定这假设我已经连接到一个特定的实例。


当前回答

在命令行中:

SQLCMD -L

or

OSQL -L

(注:必须大写L)

这将列出网络上安装的所有sql server。您可以设置一些配置选项来防止SQL Server显示在列表中。要做到这一点…

在命令行:

svrnetcn

在启用的协议列表中,选择“TCP/IP”,然后单击属性。有一个“隐藏服务器”的复选框。

其他回答

安装的所有实例都应该显示在Microsoft管理控制台的服务管理单元中。如果需要获取实例名,请执行“开始|运行|类型的服务”。查找所有带有“Sql Server(实例名)”的条目。

SQL Server浏览器服务http://msdn.microsoft.com/en-us/library/ms181087.aspx

这里有一个简单的方法: 去 然后开始 程序然后 然后是SQL Server 2005 配置工具 然后是SQL Server配置管理器 然后进行SQL Server 2005网络配置 在这里,您可以找到安装到您的机器上的所有实例。

我也有同样的问题。“osql -L”命令只显示服务器列表,但不显示实例名(只显示本地SQL server的实例)。 通过Wireshark, sqlbrowser.exe(可以在SQL安装的共享文件夹中找到),我找到了解决我的问题的方法。

本地实例由注册表项解析。远程实例通过UDP广播(端口1434)和SMB进行解析。 使用"sqlbrowser.exe -c"列出请求。

My configuration uses 1 physical and 3 virtual network adapters. If I used the "osql -L" command the sqlbrowser displayed a request from one of the virtual adaptors (which is in another network segment), instead of the physical one. osql selects the adpater by its metric. You can see the metric with command "route print". For my configuration the routing table showed a lower metric for teh virtual adapter then for the physical. So I changed the interface metric in the network properties by deselecting automatic metric in the advanced network settings. osql now uses the physical adapter.

将获得SQL server的实例 reg查询“HKLM\软件\Microsoft\Microsoft SQL Server\实例名称\SQL”

或使用 SQLCMD - l