5

While fetching data through a stored procedure in SQL Server I am getting error like

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.

I am getting this error only for accessing a particular stored procedure, not for all SP's.

jarlh
  • 42,561
  • 8
  • 45
  • 63
Nimmi
  • 680
  • 8
  • 18

3 Answers3

10

Give your database a valid owner. Try this:

ALTER AUTHORIZATION 
ON DATABASE::[YourDatabaseName]
TO [LoginUser];

or you can try to set it like

USE [dbname]
GO
sp_changedbowner 'someLogin'
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
2
ALTER AUTHORIZATION ON DATABASE::Example TO sa;
Floern
  • 33,559
  • 24
  • 104
  • 119
Vishe
  • 3,383
  • 1
  • 24
  • 23
0

Basically SQL Server login is mapped to database user and this mapping is not properly defined for SQL server principals then login will not be sucessfully for that specific user of database on that specific instance and this user is called orphan user. First, check if the orphaned user is mapped or not.

USE <database>
EXEC sp_change_users_login @Action='Report';

if not mapped then, fix the orphaned user.

USE <database>
EXEC sp_change_users_login @Action='update_one', @UserNamePattern='YOURUSERNAME', @LoginName='YOURUSERNAME';
Rudresh
  • 21
  • 2