954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Populating List from Registry error:

Hi,

I'm pulling my hair out with this one, I need to populate a combobox with a list of servers from the registry, I think the code I've used is fairly sound, but when I run the project, I get the following error, which I'm sure you're all familiar with Null Reference Exception was Unhandled Object Reference not set to an instance of an object

private void Login_Load(object sender, EventArgs e)
{
string strKey = @"HKEY_CURRENT_USER\Software\Datasym UK\Stockade SQL\Server List";

//if (IntPtr.Size == 8)
//{
// strKey = @"SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server";
//}

RegistryKey rkSqlServer = Registry.LocalMachine.OpenSubKey(strKey);
string[] instances = rkSqlServer.GetValue("InstalledInstances")[/COLOR]
as string[];
if (instances.GetUpperBound(0) >= 0)
{
foreach (string element in instances)
if (element == "MSSQLSERVER")
{
lstServers.Items.Add(Environment.MachineName);
}
else
{
lstServers.Items.Add(Environment.MachineName + @"\" + element);
}

}
}

As anyone any ideas as to where I may be going wrong?

Thanks,

R

RighteousDude
Newbie Poster
1 post since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

instead of getvalue - which returns a single value and as you specified no default option, if not found, it would return null..

Do you not mean getsubkeynames?

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You