8

I've restored a database and created a new user(same user from which I've logged in) as db_owner. Now when I wanted to see database diagram got an error

Database Diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use files page of Database Properties dialog box or the Alter Authorization statement to set the database owner to a valid login, then add the database support objects

Now when I tried to change ownership from Files page of Database Properties I am getting error as

Set Owner failed for Database 'ABC' . (Microsoft.SqlServer.SMO) Additional Info: an exception occurred in SMO The proposed new database owner James-PC\James is mapped as user James in this database. Parameter name: James-PC\James"

Please help me fix the issue so that I may be able to see database diagrams on this computer after restoring the database backup from another system.

7

The database owner is the login in sys.server_principals that owns the database, as defined by its SID. After a restore it may easily be the case that the login that was used to restore the database is not the login that was the previous owner of the database. (This is even more likely to happen when the database if moved between servers.)

So, there could be three settings that you are having trouble with

  1. The database owner_sid is not equal to the database's db_owner sid. You can compare this for database ABC by:

    SELECT owner_sid FROM sys.databases where name = 'ABC';

    SELECT sid from ABC.sys.database_principals WHERE name = 'dbo';

  2. Next you are getting a message saying that your proposed database owner_sid also exists as a user in sys.database_principals. We know this from the error message about mapping the proposed owner.

So your steps are:

 USE ABC;
 DROP USER James;
 ALTER AUTHORIZATION ON DATABASE::ABC TO [James-PC\James];

You dropped the user which is not needed, since you are making it the dbo. Once that is out of the way, then your login can be made the owner of the database.

EDIT: You can also use SSMS to delete the James user from ABC database. Then you could return to the Database properties File tab to set the database owner. (Sorry, I tend to think scripts.)

  • 1
    That's interesting, in Management Studio the login which was made a dbo does not appear under YOUR_DB /Security / Users, – joedotnot Oct 4 '17 at 1:57
-3
  1. right click database
  2. properties
  3. select files
  4. correct/set owner (to yourpc\you, or browse and select by clicking "...")

this worked for me in in SQL server management studio v17.1

  • 2
    I think exactly this did not work for them. – dezso Jun 26 '17 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.