Change DB owner while it's being used?

techresearch7777777 1,801 Reputation points
2021-05-19T22:17:06.453+00:00

Hello I'm trying to change the owner of an active SQL 2014 DB using:

ALTER AUTHORIZATION ON DATABASE::[TargetDB] TO LoginNameOwner;

When I run it it seems to hang and notice causes Blocking so I cancel above statement.

While running above there are Sessions that are in the Suspended, Running, Runnable statuses.

Is it correct to say that you can't run this statement while it's in some other state than Sleeping?

Thanks in advance.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,165 questions
{count} votes

Accepted answer
  1. techresearch7777777 1,801 Reputation points
    2021-05-21T18:08:10.627+00:00

    Thanks SeeyaXi-msft

    Sounds like changing the owner the DB does need to be inactive/SLEEPING mode only?


4 additional answers

Sort by: Most helpful
  1. Seeya Xi-MSFT 16,461 Reputation points
    2021-05-20T07:55:52.183+00:00

    Hi @techresearch7777777

    >Is it correct to say that you can't run this statement while it's in some other state than Sleeping?

    No. The DB owner can be changed while the DB is in use.
    In addition, If your method still does not work, you can try the following two methods:

    1. Using dbo.sp_changedbowner
      USE [TargetDB]
      GO
      EXEC dbo.sp_changedbowner @loginame = [LoginNameOwner]
      GO

    2.Using SSMS
    Go to SQL Server Management Studio >> Right Click on the Database >> Go to Properties >> Go to Files and select OWNER.
    98134-s.png

    >When I run it it seems to hang and notice causes Blocking so I cancel above statement.

    Using master.dbo.sysprocesses and sys.dm_exec_requests or sys.dm_tran_locks to check whether the process is deadlocked or blocked.


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. techresearch7777777 1,801 Reputation points
    2021-05-20T21:04:04.277+00:00

    Thanks SeeyaXi-msft

    Strange I was able to eventually change the owner using my earlier mentioned above - ALTER AUTHORIZATION ON DATABASE::[TargetDB] TO LoginNameOwner;

    But it only worked when I noticed all connections were in Sleeping status only.

    I wonder why earlier my statement was hanging and caused Blocking while there were SUSPENDED, RUNNING, RUNNABLE Statuses?


  3. techresearch7777777 1,801 Reputation points
    2021-05-24T23:51:08.947+00:00

    Thanks SeeyaXi-msft.

    0 comments No comments

  4. Carel van der merwe 0 Reputation points
    2024-06-26T11:54:21.9366667+00:00

    I encountered the same or similar problem with a particular database.

    In my situation there were CLR objects in the database and changing the owner deregisters the CLR_Appdomains.

    I waited until the system was less active before running the script again that succeeded and the appdomain was unloaded.

    I did make sure to call one of the dependent functions that make use of the CLR and ensure that it is working that registered a new appdomain.

    0 comments No comments