这是错误消息:
消息 15151,第 16 级,状态 1,第 31 行
无法更改服务器角色“ReadPurchasingOnly”,因为它不存在或您没有权限。
我尝试了这段代码(我添加了回滚点):
BEGIN TRANSACTION;
USE AdventureWorks2022;
GO
CREATE LOGIN Purchasing1
WITH PASSWORD ='2025WillBeBetter-right?',
DEFAULT_DATABASE=AdventureWorks2022,
CHECK_EXPIRATION=OFF,
CHECK_POLICY=ON
GO
CREATE USER Purchasing1
FROM LOGIN Purchasing1
WITH DEFAULT_SCHEMA = Purchasing
GO
SAVE TRANSACTION Save1;
BEGIN TRANSACTION;
CREATE ROLE ReadPurchasingOnly AUTHORIZATION [purchasing1];
GO
GRANT SELECT ON PURCHASING.ProductVendor TO ReadPurchasingOnly;
GRANT SELECT ON PURCHASING.PurchaseOrderDetail TO ReadPurchasingOnly;
GRANT SELECT ON PURCHASING.PurchaseOrderHeader TO ReadPurchasingOnly;
GRANT SELECT ON PURCHASING.ShipMethod TO ReadPurchasingOnly;
GRANT SELECT ON PURCHASING.Vendor TO ReadPurchasingOnly;
GO
ALTER SERVER ROLE ReadPurchasingOnly ADD MEMBER purchasing1;
GO
SAVE TRANSACTION Save2;
--ROLLBACK TRANSACTION
我每次都会出错。
本机:
Windows 10,已启用开发者模式
防火墙添加端口1433入站规则
软件:以管理员身份重新安装 SQL Server 2020 和 SSMS v 20.2。标准安装。
我的登录属性/服务器级别下的 SSMS:
在数据库层面:
我尝试过的:
SELECT * FROM fn_my_permissions(NULL, 'SERVER') GO;
。 50 个结果,创建/更改/模拟/查看都在那里,甚至还有一个名为“不安全的程序集”的令人震惊的结果!当我尝试使用 GUI 时: https://stackoverflow.com/posts/79333699
我怀疑你想要:
ALTER ROLE
而不是ALTER SERVER ROLE
,因为你在数据库中创建了一个角色,而不是在服务器级别。
另外,检查你的交易处理,看起来很奇怪,不需要多个交易和保存点