【C#】獲取SQL Server實(shí)例名方法
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
//遠(yuǎn)程桌面端口,判斷操作系統(tǒng)版本(64位\32位)打開(kāi)注冊(cè)表項(xiàng)
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();//取得主機(jī)名
for (int i = 0; i < str_server.Length; i++)
{
//str_server[i] = str_hostname + "\\" + str_server[i];//在SQL 實(shí)例中加上主機(jī)名
Console.WriteLine(str_server[i]);
}
localKey.Close();
該文章在 2021/3/22 23:39:11 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |