If a database becomes orphaned and has no database owner, you will get the following error message when you try to view the database properties in SSMS:
Cannot show requested dialog. (SqlMgmt)
Property Owner is not available for Database ‘[database]’. This property may not exist for this object, or may not be retrievable due to insufficient access rights.
You can use the following code to see orphaned databases.
SELECT databases.NAME AS DB_Name, server_Principals.NAME AS User_Name
LEFT OUTER JOIN sys.[server_principals]
ON [databases].owner_sid = [server_principals].sid
To assign a new owner:
EXEC sp_changedbowner 'newuser'
If you get the following error message:
Msg 15110, Level 16, State 1, Line 1.
The proposed new database owner is already a user or aliased in the database
Open up the user’s Login Properties window under Security\Logins and uncheck the Map checkbox for the database and click OK. Basically the code won’t assign them as the new owner because it thinks they are already associated with that database. Now run the sp_changedbowner command again and it will work.