获取安装的服务器实例的名称 [英] Getting the names of server instances installed

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

问题描述


vb.net中(在运行时)有什么方法可以获取已经安装的服务器实例的名称?

谢谢

Hi,
Is there any way in vb.net (at runtime) to get the names of server instances already installed?

Thanks

推荐答案

尝试:
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


下面的代码完成工作

添加
The code below does the job

Add
Imports Microsoft.Win32

To the name space and then use following code in a button

Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names")
       For Each sk As String In key.GetSubKeyNames()
           Dim rkey As RegistryKey = key.OpenSubKey(sk)
           For Each s As String In rkey.GetValueNames()
               ListBox1.Items.Add(s)
           Next
       Next


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

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