The server principal is not able to access the database under the current security context in SQL Server MS 2012

后端 未结 10 926
-上瘾入骨i
-上瘾入骨i 2020-12-13 01:46

I am trying to access my hosting server’s database through SQL Server Management Studio, everything till login is fine but when I use the command use myDatabase

10条回答
  •  情深已故
    2020-12-13 02:39

    We had the same error even though the user was properly mapped to the login.

    After trying to delete the user it was discovered that a few SPs contained "with execute as" that user.

    The issue was solved by dropping those SPs, dropping the user, recreating the user linked to login, and recreating the SPs.

    Possibly it got in this state from restoring from backup (during a time when the related login didn't exist) or bulk schema syncing (if its possible to create an SP with execute as even though the user doesn't exist. Could also have been related to this answer.

提交回复
热议问题