tags:

views:

30

answers:

0

Following code is throwing ManagementException: "Invalid Namespace". Any idea?

private ManagementClass GetManagementObject()
{
    const String client = @"localhost";
    const String sqlServerAliasScope = @"SqlServerAlias";
    const String aliasScopePart = @"\root\Microsoft\SqlServer\ComputerManagement10";

    ManagementScope scope = new ManagementScope(@"\\" + client + aliasScopePart);
    ManagementClass clientAlias =
        new ManagementClass(scope, new ManagementPath(sqlServerAliasScope), null);
    clientAlias.Get(); // *** THROWS HERE ***

    return clientAlias;
}

This PS script also fails, which should if above fails after all:

Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10 -class SqlServerAlias

Am I missing anything to install the server maybe?