• sanket kokane (11/16/2012)


    --Drop previous reporting database

    ----------------------------------------------------------

    PRINT 'Check if DB exists if so drop'

    GO

    IF EXISTS(SELECT * FROM SYS.DATABASES WHERE NAME='ReportDB')

    BEGIN

    --Remove any connections

    ALTER DATABASE ReportDB

    SET SINGLE_USER WITH

    ROLLBACK IMMEDIATE

    --Drop DB

    DROP DATABASE ReportDB

    END

    GO

    setting db in single user mode can kill you .

    there are chances,that after putting db in single user mode,one of your application session can act as single user and you will not get access to database.

    Also why you are dropping database , use REPLACE option instead.

    Regarding single user mode, is there a better alternative way to kill the connections to the database?

    I will change that to replace rather then drop good point!

    Thanks