怎么知道局域网那个台电脑有SQL服务器
1、在VS2017中新建项目,并选择建立Windows窗体应用,如下图:

3、在类库SqlLocator中,输入C# 代码,用于获取局域网内的所有数据库服务器的名称: public static string[] GetLocalSqlServerNamesWithSqlClientFactory() { DataTable dataSources = SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources(); DataColumn column2 = dataSources.Columns["ServerName"]; DataColumn column = dataSources.Columns["InstanceName"]; DataRowCollection rows = dataSources.Rows; string[] array = new string[rows.Count]; for (int i = 0; i < array.Length; i++) { string str2 = rows[i][column2] as string; string str = rows[i][column] as string; if (((str == null) || (str.Length == 0)) || ("MSSQLSERVER" == str)) { array[i] = str2; } else { array[i] = str2 + @"\" + str; } } Array.Sort<string>(array); return array; }

5、编码完成,点击绿色的“启动”按钮,执行本程序。
