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


当前回答

如果您有兴趣在脚本中确定这一点,您可以尝试以下方法:

sc \\server_name query | grep MSSQL

注意:grep是gnuwin32工具的一部分

其他回答

在命令行中:

SQLCMD -L

or

OSQL -L

(注:必须大写L)

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

在命令行:

svrnetcn

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

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

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

If you just want to see what's installed on the machine you're currently logged in to, I think the most straightforward manual process is to just open the SQL Server Configuration Manager (from the Start menu), which displays all the SQL Services (and only SQL services) on that hardware (running or not). This assumes SQL Server 2005, or greater; dotnetengineer's recommendation to use the Services Management Console will show you all services, and should always be available (if you're running earlier versions of SQL Server, for example).

If you're looking for a broader discovery process, however, you might consider third party tools such as SQLRecon and SQLPing, which will scan your network and build a report of all SQL Service instances found on any server to which they have access. It's been a while since I've used tools like this, but I was surprised at what they found (namely, a handful of instances that I didn't know existed). YMMV. You might Google for details, but I believe this page has the relevant downloads: http://www.sqlsecurity.com/Tools/FreeTools/tabid/65/Default.aspx

我刚刚安装了Sql server 2008,但我无法连接到任何数据库实例。 @G Mastros发布的命令没有列出活动实例。

因此,我查看了服务,发现SQL server代理被禁用。我把它设置为自动,然后再启动。