none
Force to close existing connections when restoring existing database

    Question

  • 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

    Monday, August 13, 2007 4:51 PM

Answers

  •  

    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

     

     

     

    Monday, August 13, 2007 5:20 PM

All replies

  •  

    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

     

     

     

    Monday, August 13, 2007 5:20 PM
  • Thanks a lot,

    Roman

    Tuesday, August 14, 2007 11:15 AM