sql-server - 在 Azure SQL 数据库上设置 RESTRICTED_USER

标签 sql-server database azure permissions

我正在尝试将 Azure SQL 数据库设置为 RESTRICTED_USER 模式,但遇到了我自己无法弄清楚的奇怪错误。

Msg 5011, Level 14, State 2, Line 1
User does not have permission to alter database 'YourDB', the database does not exist, or the database is not in a state that allows access checks.

According to the documentation membership in database db_owner role should be enough. User is also given ALTER DATABASE permission.

RESTRICTED_USER allows for only members of the db_owner fixed database role and dbcreator and sysadmin fixed server roles to connect to the database, but does not limit their number. All connections to the database are disconnected in the timeframe specified by the termination clause of the ALTER DATABASE statement. After the database has transitioned to the RESTRICTED_USER state, connection attempts by unqualified users are refused.

https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-set-options

What else is needed to make database RESTRICTED_USER?

Code to reproduce:

CREATE LOGIN YourLogin WITH PASSWORD = 'password' 
GO

-- USE YourDB;
-- switch to YourDB here, Azure SQL does not support USE statement

CREATE USER YourUser
    FOR LOGIN YourLogin
    WITH DEFAULT_SCHEMA = dbo

GRANT ALTER TO YourDB

EXEC sp_addrolemember N'db_owner', N'YourUser'

那么,下面的语句就会失败。

ALTER DATABASE YourDB SET RESTRICTED_USER;

最佳答案

我尝试重现该问题,但只有系统管理员可以将数据库状态更改为restricted_user。

您还提到文档指出数据库 db_owner 角色的成员资格应该足够了

但是文档指出,当数据库设置为restricted_user模式时,可以连接到数据库的角色

RESTRICTED_USER allows for only members of the db_owner fixed database role and dbcreator and sysadmin fixed server roles to connect to the database, but does not limit their number

综上所述,具有上述角色的用户将能够连接数据库,当设置为受限用户时,并没有说明dbmanager可以将数据库的状态更改为受限用户

关于sql-server - 在 Azure SQL 数据库上设置 RESTRICTED_USER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43346268/

相关文章:

c# - 使用 C#(或任何其他方法)将 XML 转换为 SQL Server 表

database - 将 Heroku 应用程序指向 AWS RDS 数据库

php - PDO 连接到多个数据库

Android:如何创建从数据库进行身份验证的登录页面

azure - 将 WebJob 添加到 Azure 应用服务 - 权限问题

sql-server - 历史表的优点、缺点和陷阱 - 使用触发器、存储过程或在应用程序级别

sql - SYSDATETIME() 是否比 GETDATE() 花费更多?

sql - 从VBA中的数组批量插入到sql中

python - FastCGI 进程超出了配置的请求超时 - Azure 应用服务

azure - 使用 Terraform 更新 Azure KeyVault 的防火墙规则