You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行SQL Server Grant权限时遇“找不到2参数重载”MethodException错误

解决方法

问题出在参数类型不匹配:EnumServerPermissions返回的是ServerPermissionInfo对象集合,而Grant方法需要的是ServerPermissionSet类型的参数,不能直接传入枚举出来的权限信息。

执行以下步骤修正:

  1. 从$sps中提取权限类型,创建对应的ServerPermissionSet对象
  2. 使用正确的参数调用Grant方法
# 提取权限类型,构建ServerPermissionSet
$permissionSet = New-Object Microsoft.SqlServer.Management.Smo.ServerPermissionSet
foreach ($sp in $sps) {
    $permissionSet.Add($sp.PermissionType)
}

# 执行授权操作
$server.Grant($permissionSet, "hlk-s19\hlk")
额外验证要点

如果仍有报错,检查以下内容:

  • 确认SqlServer模块版本:执行Get-Module SqlServer,确保版本兼容你的SQL Server 2019(15.x),建议安装对应版本的最新兼容模块
  • 查看Grant方法签名:执行$server | Get-Member -Name Grant,确认方法需要的参数类型为ServerPermissionSet和被授权用户(字符串/字符串数组)
  • 确认当前PowerShell执行账号拥有SQL Server的授权操作权限

内容的提问来源于stack exchange,提问作者nwolff

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 23:36:01