Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restore Backup

Status
Not open for further replies.

DroopyA

Programmer
Aug 5, 2003
52
0
0
US
I keep getting this error while trying to restore the
database:

"Exclusive Access could not be obtained because the
database is in use. RESTORE database is terminating
abnormally."

I am sure though that no one has logged onto the system
while I am doing the restore but I keep getting this error. Any clues?

Thanks.
-N473
 
Use query analyzer and run the system stored proc sp_who2 or sp_who this will details of all connections.
 
Which database are you trying to restore? If the Master then it must be started in single user mode. If other database then you probabely have the dile opened. Stop any other service which use the database you are tryingto backup.
 
Well, here is the catch. This is actually part of another program that my company is selling. So this should be automatic in the sense that the user presses "Restore" and we restore their last backup. This is also done using MSDE not the actual SQL Server program (although MSDE is SQL without the front end). Even if I run sp_who, it won't tell me much since the users returned will mean nothing to me. That is, unless of course there is a way to log the user off through a command....

Let me ask you this, is their a way that I can log off all users currently using the database? If so, will it log everybody off of SQL Server or just that database?

Thanks for your help
-N473
 
To restore ANY database, it must not be in use. It should be set for SINGLE-USER. (I don't use MSDE, so I don't know the commands for that).

To 'kick' users out of a database, issue the KILL command:

KILL SPID(xx)

The SPID is the system process ID. When you do a sp_who command, it returns the SPID number (xx). Use that to KILL the user connection.

-SQLBill
 
Ok, lets work with that. So the user clicks Restore and the program finds out that there are other users currently logged into the SQL Server. Now I bring up a message box saying "Users are loged on do you want to kick them out". If they click yes, then I need to run "sp_who", get their ID numbers, and kill them from the system. Wonderful, this will work. But one last question that hopefully you can answer. In code (Visual Basic) when I execute "sp_who" how do I get the returned ID numbers?

Thanks
-N473
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top