获取已安装的服务器实例列表 [英] Getting list of server instances installed

查看:77
本文介绍了获取已安装的服务器实例列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用以下代码来获取已安装的服务器实例列表。



Hi,
I am using following code to get a list of server instances installed.

Dim sqldatasourceenumerator1 As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
        datatable1 = sqldatasourceenumerator1.GetDataSources()





有时候这段代码工作正常,但大部分时间都会丢失,系统会无法响应。



有没有人可以告诉我一些在所有条件下都可靠的替代代码?

谢谢



Sometimes this code works fine but most of the times it gets lost and system becomes unresponsive.

Could any body advise me some alternative code that is reliable in all conditions?
Thanks

推荐答案

这与我使用的完全一样,对我来说永远都不会失败(但是检查网络上每个可能的地址可能需要一段时间):

C#:

That is exactly the same as I use, and it never fails for me (but it can take a while to check every possible address on the network):
C#:
SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
DataTable dt = instance.GetDataSources();
foreach (System.Data.DataRow row in dt.Rows)
    {
    Console.WriteLine("ServerName = {0}", row["ServerName"]);
    }

VB:

VB:

Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim dt As DataTable = instance.GetDataSources()
For Each row As System.Data.DataRow In dt.Rows
    Console.WriteLine("ServerName = {0}", row("ServerName"))
Next

所以我怀疑问题是不是代码,而是环境:看你的网络!

So I suspect the problem is not the code, but the environment: look to your network!


这篇关于获取已安装的服务器实例列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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