【问题标题】:Error dropping or deleting a user from SQL Server 2012从 SQL Server 2012 删除或删除用户时出错
【发布时间】:2014-05-21 02:05:31
【问题描述】:

我正在尝试从 SQL Server 中删除所有登录名,但默认的内置 SQL Server 登录名除外,但我无法删除“\administrator”帐户。它给了我一个错误:

“服务器主体 '\administrator' 已授予一个或多个权限。在删除服务器主体之前撤销权限。”

我尝试使用此查询检查分配给该用户的权限:

Select * 
  from sys.server_permissions 
 where grantor_principal_id = 
           (Select principal_id 
              from sys.server_principals 
              where name = N'<domain>\administrator')

这个查询只返回一个与终点对应的记录,如下所示:

class   class_desc  major_id    minor_id    grantee_principal_id    grantor_principal_id    type    permission_name state   state_desc

105 ENDPOINT    65536   0   269 259 CO      CONNECT G   GRANT

但是,当我尝试使用对象资源管理器在任何现有端点上检查分配给该用户的权限时,我发现没有人对我要删除的用户具有任何类型的权限。

我不确定发生了什么以及在哪里寻找删除该用户。 任何帮助将不胜感激。

【问题讨论】:

    标签: sql sql-server security permissions endpoint


    【解决方案1】:

    我能够解决这个问题。以下两个问题不允许我从 sql server 删除“\administrator”登录:

    1. 发现“ReportServer”和“ReportServerDB”的所有者是“\administrator”用户
    2. 发现“ConfigMgrEndPoint”端点的所有者是“\administrator”用户。

    我将它们都更改为“sa”用户,然后我成功地删除了该用户。我还从帮助我解决这个问题的一位同事那里得到了以下专家评论:

    将 [sa] 作为大多数 sql 对象的默认所有者是一个好习惯。如果将来 Active Directory 中不再存在该用户,则将域用户设置为 SQL 对象的所有者可能会影响以后的工作。

    【讨论】:

      【解决方案2】:

      找出阻止登录的权限是什么 我正在使用this 脚本:

      SELECT @@SERVERNAME,@@SERVICENAME
      SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
      
      DECLARE @GrantorName nvarchar(4000)
      
      SET @GrantorName = 'xxx\the_login'  /* Login in Question */
      
      SELECT b.name as Grantor
      , c.name as Grantee
      , a.state_desc as PermissionState
      , a.class_desc as PermissionClass
      , a.type as PermissionType
      , a.permission_name as PermissionName
      , a.major_id as SecurableID 
      FROM sys.server_permissions a
      JOIN sys.server_principals b
      ON a.grantor_principal_id = b.principal_id
      JOIN sys.server_principals c
      ON a.grantee_principal_id = c.principal_id
      WHERE grantor_principal_id =
      (
       SELECT principal_id
       FROM sys.server_principals
       WHERE name = @GrantorName
      )
      

      有时this 一个:

      --Check to see if they own the endpoint itself:
      SELECT SUSER_NAME(principal_id) AS endpoint_owner ,name AS endpoint_name
      FROM sys.database_mirroring_endpoints;
      
      --If so, you'll need to change the endpoint owner. Say the endpoint is called Mirroring, and you want to change the owner to SA:
      --ALTER AUTHORIZATION ON ENDPOINT::Mirroring TO sa;
      

      或关注these 委托:

      --1)  Check to see if this logon only has server level permissions and check to see 
      --if this login has granted permissions to another server principal. 
      --Use this query to identify the permissions granted.
      
      Select perm.* from sys.server_permissions  perm
      INNER JOIN sys.server_principals prin ON perm.grantor_principal_id = prin.principal_id
      where prin.name = 'xxx\the_login'   /* Login in Question */
      
      --2) The permissions granted will need to be revoked , to allow the DROP LOGIN to complete. 
      --The permissions can be granted again by a suitable LOGIN.
      

      还有一篇非常不错的文章与此相关:

      Drop Login issues for logins tied to SQL Server Availability Groups

      【讨论】:

        【解决方案3】:

        您必须检查“服务器权限”和“显式权限”。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-05-11
          • 1970-01-01
          • 1970-01-01
          • 2016-01-06
          • 1970-01-01
          • 2014-10-29
          • 1970-01-01
          • 2011-01-02
          相关资源
          最近更新 更多