• This technique works for me. It guarantees success when there are apps are running with sysadmin-level permissions:

    USE YourDatabase;

    ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE; -- forcefully kills all user sessions that are not yours and rolls back open transactions

    RESTORE DATABASE ...

    The fact that you change into the database context before setting it to SINGLE_USER makes sure that user is you 🙂

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato