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 key contains a null value. Therefore, the OpenSubKey() method did not return anything, likely because what you're searching for cannot be found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With