Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Microsoft.Win64.RegistryKey?!!!

Microsoft.Win64.RegistryKey?!!!

Scheduled Pinned Locked Moved ASP.NET
windows-admindatabasesql-serversysadminquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hey all, The RegistryKey refers to Microsoft.Win32.RegistryKey and I am on Windows Server 2003 with 64 bit. Do you all know if there is a reference for Microsoft.Win64.RegistryKey? The code looks like this now...debugging it shows that the value of serverName is NULL(no kidding Wink ) public string RetrieveDataSource { get { try { System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance; DataTable dt = en.GetDataSources(); RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"); //using(RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft SQL Server")) String[] instances = (String[])rk.GetValue("InstalledInstances");**(This is NULL)** if (instances.Length > 0) { foreach (string element in instances) { //add if doesn't exist if (element != "MSSQLSERVER") { serverName = String.Format(System.Environment.MachineName, element); } else { serverName = System.Environment.MachineName; } } } } catch (Exception ex) { ex2 = ex.Message; } return serverName;**(This is NULL)** } } Is there any other way of getting the instance name without this roundabout? Seemed pretty straight forward to me before i coded...now not so much. I can get the machine name directly by System.Environment.MachineName; if only there is a way to retrieve Instance name without RegistryKey hassle..i would avoid this method totally. Thanks to Sandeep, Rolcr, Disgyza and Colin Angus Mackay for helping

    Swetha

    R L A 3 Replies Last reply
    0
    • L Lost User

      Hey all, The RegistryKey refers to Microsoft.Win32.RegistryKey and I am on Windows Server 2003 with 64 bit. Do you all know if there is a reference for Microsoft.Win64.RegistryKey? The code looks like this now...debugging it shows that the value of serverName is NULL(no kidding Wink ) public string RetrieveDataSource { get { try { System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance; DataTable dt = en.GetDataSources(); RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"); //using(RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft SQL Server")) String[] instances = (String[])rk.GetValue("InstalledInstances");**(This is NULL)** if (instances.Length > 0) { foreach (string element in instances) { //add if doesn't exist if (element != "MSSQLSERVER") { serverName = String.Format(System.Environment.MachineName, element); } else { serverName = System.Environment.MachineName; } } } } catch (Exception ex) { ex2 = ex.Message; } return serverName;**(This is NULL)** } } Is there any other way of getting the instance name without this roundabout? Seemed pretty straight forward to me before i coded...now not so much. I can get the machine name directly by System.Environment.MachineName; if only there is a way to retrieve Instance name without RegistryKey hassle..i would avoid this method totally. Thanks to Sandeep, Rolcr, Disgyza and Colin Angus Mackay for helping

      Swetha

      R Offline
      R Offline
      Ryomin
      wrote on last edited by
      #2

      I posted this on a different thread of yours but I figured I'd post it here as perhaps a different approach to your problem. I'm not entirely sure if this will work for you, but you can certainly give it a shot. You could try using this:

      using(Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer m = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer())
      {
      foreach (ServerInstance si in mc.ServerInstances)
      {
      Response.Write("ServerInstance:" + si.Name + "
      ");
      }
      }

      You'll probably have to add a Reference to Microsoft.SqlServer.Smo Best of luck

      Cheers Disgyza Programmer Analyst

      L 1 Reply Last reply
      0
      • L Lost User

        Hey all, The RegistryKey refers to Microsoft.Win32.RegistryKey and I am on Windows Server 2003 with 64 bit. Do you all know if there is a reference for Microsoft.Win64.RegistryKey? The code looks like this now...debugging it shows that the value of serverName is NULL(no kidding Wink ) public string RetrieveDataSource { get { try { System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance; DataTable dt = en.GetDataSources(); RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"); //using(RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft SQL Server")) String[] instances = (String[])rk.GetValue("InstalledInstances");**(This is NULL)** if (instances.Length > 0) { foreach (string element in instances) { //add if doesn't exist if (element != "MSSQLSERVER") { serverName = String.Format(System.Environment.MachineName, element); } else { serverName = System.Environment.MachineName; } } } } catch (Exception ex) { ex2 = ex.Message; } return serverName;**(This is NULL)** } } Is there any other way of getting the instance name without this roundabout? Seemed pretty straight forward to me before i coded...now not so much. I can get the machine name directly by System.Environment.MachineName; if only there is a way to retrieve Instance name without RegistryKey hassle..i would avoid this method totally. Thanks to Sandeep, Rolcr, Disgyza and Colin Angus Mackay for helping

        Swetha

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        public string RetrieveDataSource { get { try { System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance; DataTable dt = en.GetDataSources(); RegisteredServer[] rsvrs = Microsoft.SqlServer.Management.Smo.SqlServerRegistrations.EnumRegisteredServers(); foreach (RegisteredServer rs in rsvrs) { serverName = rs.ServerInstance; } } catch (Exception ex) { ex2 = ex.Message; } return serverName; } } The returned string is "machine name"\sqlexpress. Atleast this returns something instead of object reference error. Now the next question is, the Sql server instance the solution is accessing is MSSQLSERVER2008, now why would it show Sqlexpress in the output? If the answer is because its default, how to find the instance which is being currently used. Thanks.

        Swetha Sankaran

        R 2 Replies Last reply
        0
        • R Ryomin

          I posted this on a different thread of yours but I figured I'd post it here as perhaps a different approach to your problem. I'm not entirely sure if this will work for you, but you can certainly give it a shot. You could try using this:

          using(Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer m = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer())
          {
          foreach (ServerInstance si in mc.ServerInstances)
          {
          Response.Write("ServerInstance:" + si.Name + "
          ");
          }
          }

          You'll probably have to add a Reference to Microsoft.SqlServer.Smo Best of luck

          Cheers Disgyza Programmer Analyst

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Though it seemed like it would work, it showed error in ServerInstance keyword. Added a bunch of assembly reference using Microsoft.SqlServer.Management.Smo.Wmi; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo.RegisteredServers; Looks like i'm pretty close, if only i could figure out how to find the sql server instance running, i'll be all set to post an article about the exercise :laugh:

          Swetha

          1 Reply Last reply
          0
          • L Lost User

            public string RetrieveDataSource { get { try { System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance; DataTable dt = en.GetDataSources(); RegisteredServer[] rsvrs = Microsoft.SqlServer.Management.Smo.SqlServerRegistrations.EnumRegisteredServers(); foreach (RegisteredServer rs in rsvrs) { serverName = rs.ServerInstance; } } catch (Exception ex) { ex2 = ex.Message; } return serverName; } } The returned string is "machine name"\sqlexpress. Atleast this returns something instead of object reference error. Now the next question is, the Sql server instance the solution is accessing is MSSQLSERVER2008, now why would it show Sqlexpress in the output? If the answer is because its default, how to find the instance which is being currently used. Thanks.

            Swetha Sankaran

            R Offline
            R Offline
            Ryomin
            wrote on last edited by
            #5

            You should probably verify that there is only one ServerInstance being returned. Because you are using a foreach loop and overwriting the serverName value it will always show you the last ServerInstance. If you have more than one ServerInstance this may become a problem. Perhaps you can store the value of the ServerInstance in the Web.config file in the AppSettings? I'm heading home for the weekend and won't be able to check up on this post anymore until Monday. I wish you the best of luck Swetha. I'm sure you will find a solution.

            Cheers Disgyza Programmer Analyst

            1 Reply Last reply
            0
            • L Lost User

              public string RetrieveDataSource { get { try { System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance; DataTable dt = en.GetDataSources(); RegisteredServer[] rsvrs = Microsoft.SqlServer.Management.Smo.SqlServerRegistrations.EnumRegisteredServers(); foreach (RegisteredServer rs in rsvrs) { serverName = rs.ServerInstance; } } catch (Exception ex) { ex2 = ex.Message; } return serverName; } } The returned string is "machine name"\sqlexpress. Atleast this returns something instead of object reference error. Now the next question is, the Sql server instance the solution is accessing is MSSQLSERVER2008, now why would it show Sqlexpress in the output? If the answer is because its default, how to find the instance which is being currently used. Thanks.

              Swetha Sankaran

              R Offline
              R Offline
              Ryomin
              wrote on last edited by
              #6

              Hi Swetha, I got the results you were looking for. In my case this returns more than one instance. But it does work. Try using this

              Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer mc = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer();
              foreach (Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance si in mc.ServerInstances)
              {
              Response.Write("ServerInstance: " + si.Name);
              }

              In my case it returns two instances MSSMLBIZ SQLEXPRESS

              Cheers Disgyza Programmer Analyst

              L 1 Reply Last reply
              0
              • R Ryomin

                Hi Swetha, I got the results you were looking for. In my case this returns more than one instance. But it does work. Try using this

                Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer mc = new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer();
                foreach (Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance si in mc.ServerInstances)
                {
                Response.Write("ServerInstance: " + si.Name);
                }

                In my case it returns two instances MSSMLBIZ SQLEXPRESS

                Cheers Disgyza Programmer Analyst

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Hey cool..will try it rightaway...thanks disgyaza. You have an awesome weekend!!

                Swetha

                1 Reply Last reply
                0
                • L Lost User

                  Hey all, The RegistryKey refers to Microsoft.Win32.RegistryKey and I am on Windows Server 2003 with 64 bit. Do you all know if there is a reference for Microsoft.Win64.RegistryKey? The code looks like this now...debugging it shows that the value of serverName is NULL(no kidding Wink ) public string RetrieveDataSource { get { try { System.Data.Sql.SqlDataSourceEnumerator en = System.Data.Sql.SqlDataSourceEnumerator.Instance; DataTable dt = en.GetDataSources(); RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"); //using(RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft SQL Server")) String[] instances = (String[])rk.GetValue("InstalledInstances");**(This is NULL)** if (instances.Length > 0) { foreach (string element in instances) { //add if doesn't exist if (element != "MSSQLSERVER") { serverName = String.Format(System.Environment.MachineName, element); } else { serverName = System.Environment.MachineName; } } } } catch (Exception ex) { ex2 = ex.Message; } return serverName;**(This is NULL)** } } Is there any other way of getting the instance name without this roundabout? Seemed pretty straight forward to me before i coded...now not so much. I can get the machine name directly by System.Environment.MachineName; if only there is a way to retrieve Instance name without RegistryKey hassle..i would avoid this method totally. Thanks to Sandeep, Rolcr, Disgyza and Colin Angus Mackay for helping

                  Swetha

                  A Offline
                  A Offline
                  AlexeiXX3
                  wrote on last edited by
                  #8

                  Stop posting and deleting

                  Alexei Rodriguez

                  L 1 Reply Last reply
                  0
                  • A AlexeiXX3

                    Stop posting and deleting

                    Alexei Rodriguez

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    I WILL continue to update the code and WILL delete that which is obsolete. The code that was deleted were updated and posted back based on further research and modifications.

                    Swetha

                    A 1 Reply Last reply
                    0
                    • L Lost User

                      I WILL continue to update the code and WILL delete that which is obsolete. The code that was deleted were updated and posted back based on further research and modifications.

                      Swetha

                      A Offline
                      A Offline
                      AlexeiXX3
                      wrote on last edited by
                      #10

                      swetha sankaran wrote:

                      The code that was deleted were updated and posted back based on further research and modifications.

                      It looks like you have no idea of what this forum is for First do "research", then if you dont find the answer, then post, and let the post grow as more people enriches the post If you continue doing that, i WILL block your account for posting

                      Alexei Rodriguez

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups