question

Lance Roberts avatar image
Lance Roberts asked

SQL Server 2008 SMS won't restore

I've been using SQL Server 2005 SMS for a few years and have had no problem backing up my database and restoring to my test database (the server being accessed is 2005 Standard). I've now had the computer upgraded, and got a new version of SQL Server 2008 R2 on my machine. The SMS now comes up with this error when trying to do a restore: >**Exclusive access could not be obtained because the database is in use.** I'm the only user of the test database, and it only gets queried occasionally so it's never always being used. Any ideas on how I can do my restores now? **sp_who2:** ![spwho2][1] **Error Screenshot: (note, the server is NOT running sqlexpress, we just left the name when we upgraded** ![Restore Error][2] **EDIT:** In the end, we rebooted the server and the problem went away. Thanks for the help. [1]: /upfiles/spwho2_1.png [2]: /upfiles/restoreerror.png
sql-server-2008ssmsrestore
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
Make sure you're not in the database when you try to restore it. Check the output of `sp_who` for details of who's connected. How are you attempting to restore the database?
9 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Lance Roberts avatar image Lance Roberts commented ·
sp_who shows me only, but I'm just in SMS, right-clicking on the database, and using the restore option, with the dialog box that follows.
0 Likes 0 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
and there are no records in that resultset that have your database name in the `dbname` field?
0 Likes 0 ·
Lance Roberts avatar image Lance Roberts commented ·
no, the dbname field says 'master'.
0 Likes 0 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
...for all connections? Or are you only seeing the one? what about the results from sp_who2? What version of SSMS are you using? Can you show the code that SSMS is generating? This may also help.
0 Likes 0 ·
Lance Roberts avatar image Lance Roberts commented ·
edited in a couple of screenshots, version is 10.50.1600.1
0 Likes 0 ·
Show more comments
Grant Fritchey avatar image
Grant Fritchey answered
Assuming it's not a production database and it's not you connected to the database, you can do this: ALTER DATABASE AdventureWorks SET SINGLE_USER WITH ROLLBACK IMMEDIATE But doing that on a production system is inherently dangerous. If legitimate users are on the system, this will blast them off.
6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Lance Roberts avatar image Lance Roberts commented ·
ok, tried it, but it said it `failed because a lock could not be placed on database`.
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
It sounds like you're connected to the database. Do you have it open in the Object Explorer window? If you've clicked on it there, you have a connection even if you close all the query windows where you're connected.
0 Likes 0 ·
Lance Roberts avatar image Lance Roberts commented ·
No, I just tried completely restarting SMS, and only selected the database so I could use the right-click context menu to restore, and the same result happened.
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Something is connected to the database. Oh, change the script above and try changing it to RESTRICTED_USER. See if that works.
0 Likes 0 ·
Lance Roberts avatar image Lance Roberts commented ·
ok, that gave me a success message, but the restores still give the same error.
0 Likes 0 ·
Show more comments
ThomasRushton avatar image
ThomasRushton answered
Given your screenshot from the `sp_who2` has returned only one row, it seems to me as though you're not admin on that server, therefore you can't actually see anyone else connected to your database. Is this the case?
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Lance Roberts avatar image Lance Roberts commented ·
Yes, I'm not the ultimate admin though I have full permissions on the two databases I'm working on.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.