tsql - How to gain exclusive access to SQL Server 2005 database to restore? -
whenever restore backup of database in sql server presented following error:
msg 3101, level 16, state 1, line 1 exclusive access not obtained because database in use. msg 3013, level 16, state 1, line 1 restore database terminating abnormally.
usually around restart server. fine when developing on our local instance on our development machines. have few programmers need access database, , logistics of having script changes , drop them subversion becoming nightmare. regardless our simple solution put on shared server in office , backup server in case screwed data.
well, screwed data , needed restore. unfortunately, have co-worker in office working on project , using same database server development. nice i'd restore without restarting sql server , possibly disrupting work.
is there way script in t-sql able take exclusive access or drop connections?
you can force database offline , drop connections with:
exec sp_dboption n'yourdatabase', n'offline', n'true'
or can
alter database [yourdatabase] set offline rollback after 60 seconds
rollback specifies if executing. after period rolled back. provides protection.
sorry wasn't thinking/reading right. bing online , backup. there post on stack overflow on t-sql snippet dropping connections rather binging offline first: hidden features of sql server
Comments
Post a Comment