Home > Alter, Error Messages, Logging, SQL Queries, SQL Server, T-SQL > 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.”
  1. June 25, 2010 at 9:14 am

    Great post Tijo,

    Have been searching around for quite a bit trying to figure this one out, tried your Alter suggestion and worked immediately.

    My problem was I had set up the db remotely with a user account called user01, when attaching the backup locally and trying to connect, it couldn’t find the sp’s as it expected a default dbo schema and not the user01 one. It’s too easy to think this is a permissions problem and spend ages fiddling with settings that could make the problem alot worse!

    Thanks again for posting this.



  2. Noone
    June 21, 2011 at 2:55 pm


  3. Scott
    August 16, 2011 at 7:07 pm


    DECLARE @username varchar(256)

    DECLARE fixusers CURSOR
    SELECT UserName = Name FROM sysusers
    issqluser = 1
    AND (sid IS NOT NULL AND sid 0x0)
    AND suser_sname(sid) IS NULL
    AND name NOT IN (‘dbo’, ‘guest’)
    ORDER BY Name

    OPEN fixusers

    FETCH NEXT FROM fixusers INTO @username

    PRINT ‘UserName: ‘ + @username

    EXEC sp_change_users_login ‘update_one’, @username, @username

    FETCH NEXT FROM fixusers INTO @username

    CLOSE fixusers
    DEALLOCATE fixusers

    This what we use to fix this issue in a stored procedure.

  4. hb
    November 22, 2011 at 5:54 pm

    good one

  1. November 28, 2013 at 7:27 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: