WMI:“无效命名空间”当尝试检索“SqlServerAlias”时范围

发布于 2024-09-24 15:25:51 字数 761 浏览 4 评论 0原文

以下代码抛出 ManagementException:“无效的命名空间”。有什么想法吗?

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;
}

这个 PS 脚本也失败了,如果上面失败的话应该会失败:

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

我是否缺少任何安装服务器的东西?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情泪▽动烟 2024-10-01 15:25:55

您正在查询远程服务器吗?

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

我可以成功运行此命令(没有无效的命名空间错误),但不会返回任何结果,尽管我没有配置任何别名。

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.

归属感 2024-10-01 15:25:54

这对我有用:

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

返回:

__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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文