1, do the project encountered this situation : The original Test_dev database, want to copy out test_ft for testing purposes. At this time backup Test_dev out Test_backup file, want to directly revert to TEST_FT will report the use of errors.
Restore DATABASE: The backup set holds a backup of a database other than the existing database cannot gain exclusive access to the database because it is in use
2, Reason: (1) The backup file contains the original database and file name information, the default will be restored to the Test_dev database, and file file is still test_dev.mdf and test_dev_log.ldf files. Test_ft and its files already exist in the server and folder, so the database and file occupancy conflicts will occur.
(2) If the database name and file file name are modified to test_ft, the test_ft restore succeeds, and the original Test_dev database is always in the restored state
3. Solutions
Scenario One: (1) detach the Test_dev database or take it offline
(2) Do not need to create test_ft database in advance, directly restore, the database name is changed to Test_ft, the corresponding file name is changed to Test_ft.mdf and Test_ft_log.ldf
(3) Additional or online Test_dev
Scenario Two: (1) do not need to create test_ft database in advance, directly restore, the database name is changed to Test_ft, the corresponding file name is changed to Test_ft.mdf and Test_ft_log.ldf
(2) In this case, unfortunately, cause 2, delete the Test_dev library
(3) Restore the Test_dev library again
4, attached: The general situation of the database is occupied by the processing method
Set up the database to work in single-user mode.
Setup method: Right-click on the database you want to restore, select Properties on the right-click menu command > Options-> Status-> Restrict Access-> "single"
SQL Server Backup restores database times usage errors