| | |
Populating List from Registry error:
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
![]() |
Other Threads in the C# Forum
- Previous Thread: LINQ stored procedure to select all data from table to datagridview
- Next Thread: Get a List of Installed Drivers
| Thread Tools | Search this Thread |
.net access algorithm array asp.net barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot math mouseclick movingimage mysql mysql.data.client operator path photoshop picturebox pixelinversion platform post programming radians regex remote remoting resourcefile richtextbox server sleep socket sql statistics stream string system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml






