Tuesday, December 28, 2010

Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be impersonated, or you do not have permission.

during Replication i faced this issue reason was simple that user prefix was not working properly in SQL server 2005. here is how to do it.

This problem occurs because SQL Server 2005 cannot obtain the information about the context when you try to impersonate a database user to run a statement or a module.

SQL Server cannot obtain the information about the context that you are trying to impersonate under the conditions that are listed in the "Symptoms" section. If you impersonate a SQL Server authorization login, SQL Server cannot find a login that matches the security identifier (SID) of the impersonated user. If you impersonate a domain user, the domain controller cannot find the information about the specific user who matches the SID of the impersonated user.

To work around this problem, change the database owner to a valid login or domain user. To do this, run the following statements:

sp_changedbowner ''

Note represents the name of the database. represents the name of the login that you want to set.
related one
the best way to do it

the way to do it
USE databsename
--sp_changedbowner sa Run this first to change the owenber of the database to sa because we are processing with sa account
--ALTER AUTHORIZATION ON DATABASE::EmployeeDB TO sa then run this command to change the authorization schema.