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.

1

3 Answers 3

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'
Sign up to request clarification or add additional context in comments.

2 Comments

How to give login credential
@Nimmi:- [LoginCredential] is the user! I will update it. Sorry for the confusion.
2
ALTER AUTHORIZATION ON DATABASE::Example TO sa;

Comments

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';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.