My SQL Server 2005 doesn't restore a backup because of active connections. How can I force it?
相关问题
- sql execution latency when assign to a variable
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
相关文章
- Entity Framework 4.3.1 failing to create (/open) a
- How do you backup an apache Jackrabbit repository
- Code for inserting data into SQL Server database u
- Delete Every Alternate Row in SQL
- Linux based PHP install connecting to MsSQL Server
- SQL Azure Reset autoincrement
- How do we alias a Sql Server instance name used in
- Is recursion good in SQL Server?
I ran across this problem while automating a restore proccess in SQL Server 2008. My (successfull) approach was a mix of two of the answers provided.
First, I run across all the connections of said database, and kill them.
Then, I set the database to a single_user mode
Then, I run the restore...
Kill the connections again
And set the database back to multi_user.
This way, I ensure that there are no connections holding up the database before setting to single mode, since the former will freeze if there are.
To add to advice already given, if you have a web app running through IIS that uses the DB, you may also need to stop (not recycle) the app pool for the app while you restore, then re-start. Stopping the app pool kills off active http connections and doesn't allow any more, which could otherwise end up allowing processes to be triggered that connect to and thereby lock the database. This is a known issue for example with the Umbraco Content Management System when restoring its database
SQL Server Management Studio 2005
When you right click on a database and click
Tasks
and then clickDetach Database
, it brings up a dialog with the active connections.Detach Screen http://www.kodyaz.com/images/articles/kill-all-processes/detach-database.JPG
By clicking on the hyperlink under "Messages" you can kill the active connections.
You can then kill those connections without detaching the database.
More information here.
SQL Server Management Studio 2008
The interface has changed for SQL Server Management studio 2008, here are the steps (via: Tim Leung)
None of the above worked for me. My database didn't show any active connections using Activity Monitor or sp_who. I ultimately had to:
Not the most elegant solution but it works and it doesn't require restarting SQL Server (not an option for me, since the DB server hosted a bunch of other databases)
Try this ...
Restarting SQL server will disconnect users. Easiest way I've found - good also if you want to take the server offline.
But for some very wierd reason the 'Take Offline' option doesn't do this reliably and can hang or confuse the management console. Restarting then taking offline works
Sometimes this is an option - if for instance you've stopped a webserver that is the source of the connections.