Sunday, April 12, 2015

SID

Error:
“SqlException: The database owner SID recorded in the master database differs from the database owner SID recorded in database 'xyz'. You should correct this situation by resetting the owner of database 'xyz' using the ALTER AUTHORIZATION statement.”
I ran the below command and saw 2 different SID
Use xyz
Go
--To get owner SID recorded in the master database for the current database
SELECT owner_sid FROM sys.databases WHERE database_id=DB_ID()
Go
--To get the owner SID recorded for the current database owner
SELECT sid FROM sys.database_principals WHERE name=N'dbo'
Go


Application owner got this error message during installation application. Whey application is ran, it creates database xyz

Solution:
Step1 :Drop that database and run the app.During application running , just watch the database and run the below command whenever you will see database xyz is created. You should run it as soon as you can.
Use xyz
Go
ALTER AUTHORIZATION ON Database::XYX TO [sa]
Go
--I used lower case for sa because my server was in case sensitive collation
--Then run below script
ALTER AUTHORIZATION ON Database::Summix_fsdb TO [Domain\user]
Go
--Application requires domain user for this app for my case
 Step2 : I ran the below command and I saw SID is sameUse xyzGo
--To get owner SID recorded in the master database for the current database
SELECT owner_sid FROM sys.databases WHEREdatabase_id=DB_ID()
Go
--To get the owner SID recorded for the current database owner
SELECT sid FROM sys.database_principalsWHERE name=N'dbo'
Go