如何使用代码列出本地计算机上的所有sql服务器名称? [英] How to list all sql server names on local machine using code?

查看:91
本文介绍了如何使用代码列出本地计算机上的所有sql服务器名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Sql server编程了几个月,但是我通常将(local)"或"localhost"传递给sqlconnection字符串.现在,我需要连接到指定的服务器,我想我必须将Sql Server名称传递到连接字符串中.但是我不在乎安装Sqlserver时的名称.您能否让我知道如何再次查看这些名称?我也想列出我计算机上的所有服务器名称,我已经用Google搜索了几个小时,但结果仍然让我感到困惑.有些建议使用注册表,但我只能找到sql服务器的实例而不是服务器名称,有些建议使用SQLSMO但可以为我列出所有服务器名称吗?(或仅列出实例)(我还没有尝试过),有些有人建议使用SqlDataSourceEnumerator类,但我已经对其进行了测试,但未得到任何预期的结果,微软表示它有时可能无法始终正常工作,我认为这对我来说是无奈的.
您能否请剖析以上方法或给我其他解决方案?
您的帮助将不胜感激!
非常感谢!

I have programmed with Sql server for some months but I usually pass "(local)" or "localhost" into the sqlconnection string. Now I need to connect to a specified server and I guess I have to pass a Sql Server name into the connection string. But I didn''t care what the names were when I installed Sqlserver. Could you please let me know how to view those names again? I also want to list all the server names on my computer and I have googled for hours but the results still confuse me. Some ones suggest using Registry but I can only find INSTANCES of sql server not server names, some ones suggest using SQLSMO but can it list all server names for me?(or only instances) (I haven''t tried this yet), some ones suggest using SqlDataSourceEnumerator class but I have tested it without any expected result, Microsoft says it can work sometimes not always and I think it is helpless to me.
Could you please dissect the methods above or give me any other solutions?
Your helps would be highly appreciated!
Thank you very much!

推荐答案

看看此链接.

Have a look at this link.

Find SQL Server Instances - C#


此处是代码项目文章. 在本地网络上查找SQL Server实例 [
here is code project article. Locate SQL Server instances on the local network[^]


这篇关于如何使用代码列出本地计算机上的所有sql服务器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆