Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
MrTexasFreedom
Starting Member
13 Posts |
Posted - 2010-12-08 : 19:45:13
|
Folks,I'm trying to replace an existing database with a restoration from another source. I can't do a restore directly because I have these client processes that keep connecting to the DB as fast as I kill them. I don't have control over those clients.I've got my restored database as a different logical name (new_Test562)on the server. I just need to get rid of the old database (Test562)and rename the new one to it's current name (Test562). exec sp_whokill 99kill 103kill 104kill 117gouse mastergoALTER DATABASE Test562 SET ONLINEgoALTER DATABASE Test562 SET SINGLE_USER WITH NO_WAITgoALTER DATABASE Test562 MODIFY NAME = old_Test562goALTER DATABASE new_Test562 MODIFY NAME = Test562go Msg 5070, Level 16, State 2, Line 1Database state cannot be changed while other users are using the database 'Test562'Msg 5069, Level 16, State 1, Line 1ALTER DATABASE statement failed.Msg 5030, Level 16, State 2, Line 1The database could not be exclusively locked to perform the operation.Any suggestions for preventing these clients from connecting while I'm trying to rename the existing database would be wonderful!Appreciatively,MrTexasFreedom |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2010-12-09 : 03:10:59
|
Or you can change the database to OFFLINE (using ROLLBACK IMMEDIATE as above). My preference is SINGLE_USER but if you are going to need to reboot, say, it may be preferable to use OFFLINE so nothing else connects to the database after the reboot. |
|
|
|
|
|
|
|