【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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |