[sql-server] SQL Server : login success but "The database [dbName] is not accessible. (ObjectExplorer)"

Please try this script.. What this script does is it looks at the active sessions of the database and kills them so you can bring the database back online.

 CREATE TABLE #temp_sp_who2
        (
          SPID INT,
          Status VARCHAR(1000) NULL,
          Login SYSNAME NULL,
          HostName SYSNAME NULL,
          BlkBy SYSNAME NULL,
          DBName SYSNAME NULL,
          Command VARCHAR(1000) NULL,
          CPUTime INT NULL,
          DiskIO INT NULL,
          LastBatch VARCHAR(1000) NULL,
          ProgramName VARCHAR(1000) NULL,
          SPID2 INT
          , rEQUESTID INT NULL --comment out for SQL 2000 databases

        )


    INSERT  INTO #temp_sp_who2
    EXEC sp_who2


    declare @kill nvarchar(max)= ''
    SELECT  @kill = @kill+ 'kill '+convert(varchar,spid) +';'
    FROM    #temp_sp_who2
    WHERE   DBName = 'databasename'

    exec sp_executesql @kill


  ALTER DATABASE DATABASENAME SET ONLINE WITH IMMEDIATE ROLLBACK