Showing posts with label restoring. Show all posts
Showing posts with label restoring. Show all posts

Wednesday, March 21, 2012

Force to close existing connections when restoring existing database

Hi All,

I would like to restore database using RESTORE DATABASE ... REPLACE command.

If database exists already and has any open connections this command will fail.

I would like to close all existing connections to specific database before running RESTORE DATABASE ... REPLACE command.

I can do closing from Management Studio using checkbox "Close Existing Connection" when deleting database. Actually I need to do the same but from script.

Please advice me how to do it.

Thanks in advance,

Roman

use the following query...

Code Snippet

use master;

alter database <data base>

set offline with rollback immediate

alter database <data base>

set online with rollback immediate

|||

Thanks a lot,

Roman