0

i am learned this codes in this forum.this codes was running until last week. only changed my computer: windows 10 updated last version.

i am learning sql instance name this codes.

RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server");
        String[] instances = (String[])rk.GetValue("InstalledInstances");
        if (instances.Length > 0)
        {
            foreach (String element in instances)
            {
                if (element == "MSSQLSERVER")
                    Console.WriteLine(System.Environment.MachineName);
                else
                    Console.WriteLine(System.Environment.MachineName + @"\" + element);

            }
            Console.ReadLine();
        }

occured error message : system nullreference Exception.

my registry records have InstalledInstances --> REG_MULTI_SZ --> CAKMAK

but i am reading another registry keys. for example this code running.

 RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\90");
            string test = rk.GetValue("SharedCode").ToString(); MessageBox.Show(test);

i guess after windows update my rights restriced.

please help , thank you.

Krl
  • 1
  • 1
  • This is not a duplicate. There is no indication here that the OP doesn't already know what a null pointer exception is. He's asking why he is getting a null when he is expecting a valid value because he knows the registry entry exists. Krl I suggest you edit this question to remove the duplicate flag that others have incorrectly added. – Klitos Kyriacou Sep 20 '16 at 23:08
  • 1
    Did you try running the application as admin? Did your OS/MS SQL change between 32/64 bits? Is your application set to "Any CPU" or explicitly set to 32 or 64 bits? (see http://stackoverflow.com/questions/974038/reading-64bit-registry-from-a-32bit-application). – Jacob Sep 20 '16 at 23:11
  • yess jacob , thak you prblem solved. – Krl Sep 20 '16 at 23:18
  • @KlitosKyriacou It's a duplicate because the linked-to answer doesn't just tell you what a null reference exception is, but how to debug and fix it. OP has given no indication of which line is throwing the exception and hasn't demonstrated any ability in debugging, which the linked-to answer will provide. – itsme86 Sep 20 '16 at 23:18
  • i deleted [prefer 32bit] checked. – Krl Sep 20 '16 at 23:19

0 Answers0