开发者

WMI: "Invalid Namespace" when trying to retrieve "SqlServerAlias" scope

开发者 https://www.devze.com 2023-01-17 03:08 出处:网络
Following code is throwing ManagementException: \"Invalid Namespace\". Any idea? private ManagementClass GetManagementObject()

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?


This works for me:

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

Returns:

__GENUS          : 2

__CLASS          : SqlServerAlias

__SUPERCLASS     :

__DYNASTY        : SqlServerAlias

__RELPATH        : SqlServerAlias.AliasName="SQLALIAS"

__PROPERTY_COUNT : 4

__DERIVATION     : {}

__SERVER         : SERVER

__NAMESPACE      : root\Microsoft\SqlServer\ComputerManagement10

__PATH           : 

\\SERVER\root\Microsoft\SqlServer\ComputerManagement10:SqlServerAlias.AliasName="SQLALIAS"

AliasName        : SQLALIAS

ConnectionString : 7001

ProtocolName     : tcp

ServerName       : SERVER\SQLALIAS


are you querying the remote server?

get-wmiobject -computername SERVER -list -namespace "root\Microsoft\SqlServer\ServerEvents\INSTANCE" -Class SQLServerAlias

I can run this successfully ( without invalid namespace error) but does not return any results, although i do not have any alias configured.

0

精彩评论

暂无评论...
验证码 换一张
取 消