Question

I have a SQL Server 2008 R2 implementation with Service Broker turned on for a .Net/IIS website running on the same box.

It doesn't throw an error when the global.asax application_startup event fires, however the event log is spammed every second with:

[dbo].[SqlQueryNotificationStoredProcedure-e6946263-93b8-445e-9d92-6fbd49a4b089]' running on queue 'XXXXXX.dbo.SqlQueryNotificationService-e6946263-93b8-445e-9d92-6fbd49a4b089' output the following: 'The database owner SID recorded in the master database differs from the database owner SID recorded in database 'XXXXXXX'. You should correct this situation by resetting the owner of database 'XXXXXXX' using the ALTER AUTHORIZATION statement.'

Also, the Service Broker is not correctly sending messages (for a SqlCacheDependency) - it basically doesn't work.

I have run the following query and determined there is an ownership mismatch:

SELECT
    SUSER_SNAME(d.owner_sid) AS OwnerName
    ,d.owner_sid AS OwnerSID
    ,dp.sid AS DboUserSID 
    ,SUSER_SNAME(dp.sid) AS DboUserMapping
FROM sys.databases AS d
JOIN sys.database_principals AS dp ON
    dp.name = 'dbo'
WHERE d.database_id = DB_ID();

OwnerName: usrAAAAA

OwnerSID: 0xAAAAA

DboUserMapping: sa

DboUserSID: 0x01

Most places I have seen suggest that I should use ALTER AUTHORIZATION to explicitly set "sa" as the database owner. However, I am unsure if it should be set to sa or usrAAAAA, and I'm not sure if there are any likely implications (what other things could I break? if any).

Any help on this would be greatly appreciated.

Was it helpful?

Solution

Setting the database owner to 'sa' is the most likley to work without causing other problems, but there can be some security related issues with it as explained here: are there reasons I should not set my db owner to sa?.

Note also that, depending on your application requirements and how the accounts are used, if you remove 'usrAAAAA' as the dbo, you may need to add them back in to the DB as a user, and you may also need to give them permissions (such as 'db_owner'). If this is the case, and you have set your database to TRUSTWORTHY (as is often required by Service Broker related usages), then you should probably set the owner to 'usrAAAAA' instead and try to get that to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top