You have several ways to do this:
- SmoApplication.EnumAvailableSqlServers ()
- SqlDataSourceEnumerator.Instance
- Direct access to the registry
Direct access is not a recommended MS solution because they can change keys / paths. But other solutions do not provide instances on 64-bit platforms.
SQL Server . , x86 x64. Windows 64- . RegistryView ( .NET 4) .
using Microsoft.Win32;
RegistryView registryView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
{
RegistryKey instanceKey = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", false);
if (instanceKey != null)
{
foreach (var instanceName in instanceKey.GetValueNames())
{
Console.WriteLine(Environment.MachineName + @"\" + instanceName);
}
}
}
32- 64- ( , ), :
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server