• Hi!!

    If the database is currently in use you won't be able to restore. If no one is supposed to be connected but you, then you should be able to kill every other session.

    Try this script:

    use master

    DECLARE @nameBD VARCHAR (100)

    SET @nameBD= 'YourDatabase'

    DECLARE @sql VARCHAR (500)

    SET @sql = ''

    /* This will build a kill command for every session found connected to the database */

    select @sql = @sql + ' KILL ' + CAST( spid AS VARCHAR(4 )) + '' FROM DBO.sysprocesses WHERE DB_NAME (dbid) = @nameBD AND spid > 50

    select @sql

    EXEC(@sql ) -- This EXEC will kill all the connections and let you restore.

    /* Credits go to Pinal Dave! */

    If you set it to single user mode and lost the connection to someone else, then reconnect to the instance using MASTER as your default database and set YourDatabase back to multi user to recover your connection.

    Hope it helps!

    regards