none
WMI SQL Services - Invalid Namespace RRS feed

  • Question

  • I'm using the source of AnywhereTS and get an exception when binding the WMI class information to a management object.

    ManagementScope manScope = new ManagementScope(@"\\.\root\Microsoft\SqlServer\ComputerManagement");
    ManagementClass sqlServicesMan = new ManagementClass(manScope, new ManagementPath("SqlService"), null);
    ManagementClass serverProtocolsMan = new ManagementClass(manScope, new ManagementPath("ServerNetworkProtocol"), null);
    
    sqlServicesMan.Get();
    serverProtocolsMan.Get();

    I've been searching already and I suppose there's nothing wrong with this piece.

    Note: I've set the framework to 4, just to test and yet the same issue.


    Regards, MusicDemon

    Monday, March 5, 2012 1:55 PM

Answers

  • Hi MusicDemon,

    Welcome to the MSDN forum.

    I just test it and found that you are missing a number in ComputerManagement. When I use ComputerManagement10, the error is gone.

    I am using SQL Server 2008, so it shoule be ComputerManagement10.

    If it still doesn't work after you change the code line, please feel free to let me konw.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 7, 2012 3:34 AM
    Moderator
  • We can use WMI Control to get the Version.

    To access WMI Control

    1. On the taskbar, click Start, and then click Control Panel.

    2. Double-click the Administrative Tools icon, and then double-click Computer Management.

    3. In the Computer Management console, expand Services and Applications, right-click WMI Control, and then click Properties.

    At the Properties window, click the Security tab, and then click the Root->Microsoft->SqlServer. You will see it at the first item.

    See my picture below:

    Hope it helps.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by MusicDemon Friday, March 9, 2012 2:24 PM
    Thursday, March 8, 2012 2:20 AM
    Moderator
  • I am not sure. As far as I know, it seems like only two versions for the Computer Management. One is 10, the other is no number after Management. If you are using SQL Server 2005 or early versions, I think it should be \\.\root\Microsoft\SqlServer\ComputerManagement. if you are using SQL Server 2008, I think it should be \\.\root\Microsoft\SqlServer\ComputerManagement10. For this idea, I think we can use a try and a IF stament to check it.

    Hope it helps.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by MusicDemon Friday, March 9, 2012 2:24 PM
    Friday, March 9, 2012 2:18 AM
    Moderator

All replies

  • Hi MusicDemon,

    Welcome to the MSDN forum.

    I just test it and found that you are missing a number in ComputerManagement. When I use ComputerManagement10, the error is gone.

    I am using SQL Server 2008, so it shoule be ComputerManagement10.

    If it still doesn't work after you change the code line, please feel free to let me konw.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 7, 2012 3:34 AM
    Moderator
  • Where could I find every "Version ID" that I should use as suffix? I haven't found this on any tutorial.

    Regards, MusicDemon

    Wednesday, March 7, 2012 10:17 AM
  • We can use WMI Control to get the Version.

    To access WMI Control

    1. On the taskbar, click Start, and then click Control Panel.

    2. Double-click the Administrative Tools icon, and then double-click Computer Management.

    3. In the Computer Management console, expand Services and Applications, right-click WMI Control, and then click Properties.

    At the Properties window, click the Security tab, and then click the Root->Microsoft->SqlServer. You will see it at the first item.

    See my picture below:

    Hope it helps.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by MusicDemon Friday, March 9, 2012 2:24 PM
    Thursday, March 8, 2012 2:20 AM
    Moderator
  • I see... Is there any way to have it auto-discovered?

    Regards, MusicDemon

    Thursday, March 8, 2012 9:45 AM
  • I am not sure. As far as I know, it seems like only two versions for the Computer Management. One is 10, the other is no number after Management. If you are using SQL Server 2005 or early versions, I think it should be \\.\root\Microsoft\SqlServer\ComputerManagement. if you are using SQL Server 2008, I think it should be \\.\root\Microsoft\SqlServer\ComputerManagement10. For this idea, I think we can use a try and a IF stament to check it.

    Hope it helps.


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by MusicDemon Friday, March 9, 2012 2:24 PM
    Friday, March 9, 2012 2:18 AM
    Moderator
  • Ah, thank you. I suppose that the .Net Frameword should have this added...

    Regards, MusicDemon

    Friday, March 9, 2012 2:24 PM