I am trying to get all the instance names of SQL on a machine, all the values are held in a regkey here is my code, but I keep getting a null reference exception.
private void RegLoop()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")
foreach (var v in key.GetValueNames())
{
MessageBox.Show("{0}", v);
}
}
If you receive that exception, it means that
keycontains anullvalue. Therefore, theOpenSubKey()method did not return anything, likely because what you’re searching for cannot be found.