How to gain exclusive access to SQL Server 2005 database to restore?

后端 未结 7 1914
礼貌的吻别
礼貌的吻别 2021-01-31 05:21

Whenever I restore a backup of my database in SQL Server I am presented with the following error:

Msg 3101, Level 16, State 1, Line 1
Exclusive access could not          


        
7条回答
  •  感情败类
    2021-01-31 05:40

    You can force the database offline and drop connections with:

    EXEC sp_dboption N'yourDatabase', N'offline', N'true'
    

    Or you can

    ALTER DATABASE [yourDatabase] SET OFFLINE WITH
    ROLLBACK AFTER 60 SECONDS
    

    Rollback specifies if anything is executing. After that period they will be rolled back. So it provides some protection.

    Sorry I wasn't thinking/reading right. You could bing back online and backup. There was also a post on Stack Overflow on a T-SQL snippet for dropping all connections rather than binging offline first: Hidden Features of SQL Server

提交回复
热议问题