Share via

Backing up SQL database while preventing user access

rr-4098 2,271 Reputation points
2023-12-09T09:20:27.38+00:00

I need to backup a SQL 2016 DB so I can restore the backup to another server for a migration. I planned on placing the DB in single user mode, run the backup then place it offline. My question is single user mode allows one connection at a time. Does my existing connection to the SSMS and DB count as one of these connections? Also from my understanding you cannot backup an offline DB correct? I just need to make sure data is not added to the DB while it is getting backed up.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

Erland Sommarskog 134.3K Reputation points MVP Volunteer Moderator
2023-12-09T10:58:49.4333333+00:00

One connection is one connection, and where the connection is coming from does not matter. Not that I see why this would be a problem. You would do

ALTER DATABASE db SET SINGLE_USER ON WITH ROLLBACK IMMEDIATE
go
BACKUP DATABASE db TO  ....
go
ALTER DATABASE db SET MULTI_USER

Then again, I am not sure that I see the point with setting the database to single user while you are taking the backup. The backup will include a portion of the transaction log, so that when you restore the backup, you will get what was committed when the backup completed.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.