Accidentally assign db_owner to a Domain User & unable to change Ownership

TonyJK 881 Reputation points
2023-02-17T05:07:02.92+00:00

Hi,

We are using SQL Serve 2019 and accidentally granted db_owner to a newly created domain user. We are not aware until we find that he can full access right to the database instead of read only.

Then we dropped that Login. However, it seems that it is not successful as we get "Drop member failed for DatabaseRole 'db_owner'.  (Microsoft.SqlServer.Smo)".

We tried to change database owner to "sa" but we get the following error.

Set owner failed for Database 'FinanceProd'.  (Microsoft.SqlServer.Smo)

We get similar error when we try to change dbo

EXEC sp_changedbowner 'Domain\Administrator';

Is there any suggestion ?

Thanks a lot

 

SQL Server Other
{count} votes

Accepted answer
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2023-02-17T23:30:45.47+00:00

    To drop the user from db_owner do:

    ALTER ROLE db_owner DROP MEMBER "Domain\User"
    

    But it is very clear from your post what you have actually done. Why did you try to change the database owner to sa?

    The query against sys.schemas has no relevance in this context.


1 additional answer

Sort by: Most helpful
  1. LiHongMSFT-4306 31,566 Reputation points
    2023-02-17T09:22:32.2133333+00:00

    Hi @TonyJK

    Did you drop that user from assigned Database? Otherwise, when you create new user with same name it would give such error.

    Best regards,

    Cosmog Hong


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.