如何使用 powershell 将用户添加到 SQL 服务器角色?
How to add a user to a SQL server role with powershell?
我需要一个关于如何为 Azure SQL 数据库中的用户分配固定服务器角色的工作示例。看来我什至无法访问 Roles
collection:
$DBServerBulkRole = $DBServer.Roles | where {$_.Name -eq 'bulkadmin'};
$DBServerBulkRole.AddMember($DBLoginName);
这会生成
The following exception occurred while trying to enumerate the collection: "Operation not supported on version 12.0.600 SqlAzureDatabase."
这表示:"This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use ALTER ROLE instead."
我建议您基本上在 powershell 中重写一个函数来执行相同的调用,但使用 alter role 命令。这应该可以解决您的问题。 Azure 的 SQL 实现略有不同,有些命令不可用。此外,如文档中所示,我认为这现在已被弃用。
-- Syntax for SQL Server (starting with 2012) and Azure SQL Database
ALTER ROLE role_name
{
ADD MEMBER database_principal
| DROP MEMBER database_principal
| WITH NAME = new_name
}
[;]
来自:
https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-role-transact-sql
希望对您有所帮助!
我需要一个关于如何为 Azure SQL 数据库中的用户分配固定服务器角色的工作示例。看来我什至无法访问 Roles
collection:
$DBServerBulkRole = $DBServer.Roles | where {$_.Name -eq 'bulkadmin'};
$DBServerBulkRole.AddMember($DBLoginName);
这会生成
The following exception occurred while trying to enumerate the collection: "Operation not supported on version 12.0.600 SqlAzureDatabase."
这表示:"This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use ALTER ROLE instead."
我建议您基本上在 powershell 中重写一个函数来执行相同的调用,但使用 alter role 命令。这应该可以解决您的问题。 Azure 的 SQL 实现略有不同,有些命令不可用。此外,如文档中所示,我认为这现在已被弃用。
-- Syntax for SQL Server (starting with 2012) and Azure SQL Database
ALTER ROLE role_name
{
ADD MEMBER database_principal
| DROP MEMBER database_principal
| WITH NAME = new_name
}
[;]
来自: https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-role-transact-sql
希望对您有所帮助!