• J.Faehrmann (7/23/2014)


    I don't drop it, because I want to keep the old db in case the restore fails 😉

    Bringing it offline and online again to drop the connections is elegant.

    I doubt if you will have a usable database if the restore fails, so there is really no point in not dropping it.

    FYI, if you set a database offline and online again just to disconnect users, it will be owned by the login that set it online.

    if you are doing that, I suggest doing it this way:

    execute as login = 'SA'; -- or the login you desire

    use master;

    alter database [MyTestDB] set offline with rollback immediate;

    alter database [MyTestDB] set online with rollback immediate;

    revert;

    -- or you could do this after setting it online

    use [MyTestDB];

    exec sp_changedbowner 'sa'