Populating List from Registry error:

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 1
Reputation: RighteousDude is an unknown quantity at this point 
Solved Threads: 0
RighteousDude RighteousDude is offline Offline
Newbie Poster

Populating List from Registry error:

 
0
  #1
Oct 6th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Populating List from Registry error:

 
0
  #2
Oct 6th, 2008
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC