SQL Error – The database owner SID recorded in the master database differs from the database owner SID

When trying to execute Stored Procedures on a particular Database we got the following error:

The server principal “domain\user” is not able to access the database “dbXYZ” under the current security context.

The database owner SID recorded in the master database differs from the database owner SID recorded in database ‘dbXYZ’. You should correct this situation by resetting the owner of database ‘dbXYZ’ using the ALTER AUTHORIZATION statement.

The Database was restored by a backup from Production box to a separate Dev box. I checked the Properties of the Database and the Owner property shows the Prod service account, which cannot be created on Dev machine.

So, we just need to change the Owner Name of the database by using “ALTER AUTHORIZATION” statement of sp_changedbowner system SP, as shown below:

And the error gone.

 

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com