When you detach a database and attach it to another computer, the following error may occur: when a user with limited permissions executes some stored procedures, error 15517 may occur: it cannot be executed as a database entity because the entity "DBO" does not exist, you cannot simulate this type of entity, or you do not have the required permissions.
The stored procedure that causes this error has a with execute as option, specifying the owner or another user (login name ).
For example, I used Windows authentication to log on to my computer, created a database, and created a stored procedure with the with execute as owner option in the database. Then, separate the database and attach it to another user's computer. If you run the stored procedure, the above error will be thrown.
This error occurs because the user (login name) specified by the with execute as option does not exist on the current server. When I use Windows authentication to log on to the server and create a database, the database owner is the Windows account I use. When a stored procedure is executed on the local machine, SQL Server finds the user and executes the stored procedure as the user. However, when the database is attached to another computer, the system of that computer does not have this account on my computer, and the user cannot be found during the execution of the stored procedure, therefore, an error is thrown.
To solve this error, modify the database owner. For example, run the following command:
Alter Authorization On Database :: [ <Database's name ] To [ SA ]
Change the owner of the specified database to sa. Sa exists on all SQL Server servers, so the preceding error is not displayed.