列出网络上的服务器 [英] Listing servers on a network

查看:94
本文介绍了列出网络上的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现以下代码来显示网络上SQL Server上的实例:

 私有  DisplayData( ByVal  As  DataTable)
   对于 每个 As  DataRow 表中.行
        对于 每个 col  As  DataColumn 表中.列
            Debug.Print(" ,col.ColumnName,row(col) )
        下一步
        Debug.Print(" )
   下一步
结束 
私有  Form1_Load( ByVal 发​​件人目标 对象,_
                        ByVal  e  As  System.EventArgs)_
            句柄 .加载
   ' 检索枚举器实例,然后检索数据.
    Dim 实例 As  SqlDataSourceEnumerator = _
            SqlDataSourceEnumerator.Instance
    Dim  As  System.Data.DataTable = instance.GetDataSources()
   ' 显示表的内容.
   DisplayData(表格)
   '  Console.WriteLine(按任意键继续.")
   '  Console.ReadKey()
结束  



此代码将以下内容返回到中间"窗口:
ServerName = LT-MRM-1
InstanceName =
IsClustered =
版本=
我要做的就是在组合框中列出服务器名称,但是找不到简单的解决方案.
有人可以指出我正确的方向吗?

[修改:添加的代码格式]

解决方案

是您的问题,它不能显示所有的Sql Server或您不知道如何绑定数据表到组合框?

如果是第一个的话
您需要具有 SQL Server浏览器 [ comboBox1.DataSource = table; comboBox1.ValueMember = " ; comboBox1.DisplayMember = " ;


I found the following code to show instances on SQL Servers on a network:

Private Sub DisplayData(ByVal table As DataTable)
   For Each row As DataRow In table.Rows
        For Each col As DataColumn In table.Columns
            Debug.Print("{0} = {1}", col.ColumnName, row(col))
        Next
        Debug.Print("============================")
   Next
End Sub
Private Sub Form1_Load(ByVal sender As Object, _
                       ByVal e As System.EventArgs) _
            Handles Me.Load
   ' Retrieve the enumerator instance and then the data.
   Dim instance As SqlDataSourceEnumerator = _
            SqlDataSourceEnumerator.Instance
   Dim table As System.Data.DataTable = instance.GetDataSources()
   ' Display the contents of the table.
   DisplayData(table)
   'Console.WriteLine("Press any key to continue.")
   'Console.ReadKey()
End Sub



This code returns the following to the Intermediate window:
ServerName = LT-MRM-1
InstanceName =
IsClustered =
Version =
All I want to do is make a list of server names in a combobox, but I can''t find a simple solution.
Can someone point me in the right direction?

[Modified: added code formatting]

Is your problem that it doesn''t show all the Sql Servers or that you don''t know how to bind the datatable to a combobox?

If it is the first;
You need to have
SQL Server Browser[^] runing on all the computers with Sql Server on them, and you need port 1434 open on those computers.


For the second;

comboBox1.DataSource = table;
comboBox1.ValueMember = "ServerName";
comboBox1.DisplayMember = "ServerName";


这篇关于列出网络上的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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