【C#】获取SQL Server实例名方法
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
//远程桌面端口,判断操作系统版本(64位\32位)打开注册表项
RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32);
//SQL Server端口
RegistryKey key = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL");
string[] str_server = key.GetValueNames();
string str_hostname = Dns.GetHostName();//取得主机名
for (int i = 0; i < str_server.Length; i++)
{
//str_server[i] = str_hostname + "\\" + str_server[i];//在SQL 实例中加上主机名
Console.WriteLine(str_server[i]);
}
localKey.Close();
该文章在 2021/3/22 23:39:11 编辑过 |
关键字查询
相关文章
正在查询... |