How do you get rid of users that are already in the database on the backup server when a restore starts?

I’m trying to implement log shipping as described in your log shipping article, with a few slight modifications. The question I have is how do you get rid of users that are already in the database on the backup server when a restore starts? If someone is using the read-only capabilities when the restore starts, it will blow up. Setting it to single user mode will also fail if users are connected to the database.

Answer

SQL Server doesn’t include any built in way to kill all user connections to a database, so you must script this feature yourself.

If you don’t want to write your own script, you can do a Google search and find many variations on the Internet.