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:

USE
GO
sp_changedbowner ''

Note represents the name of the database. represents the name of the login that you want to set.
http://support.microsoft.com/kb/913423
related one
http://awesomesql.wordpress.com/2010/02/08/sql-error-cannot-execute-as-the-database-principal-because-the-principal-sec_user-does-not-exist-this-type-of-principal-cannot-be-impersonated-or-you-do-not-have-permission/
http://dbaspot.com/forums/ms-sqlserver/354286-event-id-28005-error-15517-a.html
http://dbaspot.com/forums/ms-sqlserver/231821-re-cannot-view-database-properties.html
the best way to do it
http://msdn.microsoft.com/en-us/library/ms176060.aspx
http://forums.devx.com/showthread.php?t=150354

the way to do it
USE databsename
GO
--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.

No comments: