Thursday, March 8, 2012

Can't restore database

I'm trying to restore a I keep getting this message:
"exclusive access could not be obtained because the
database is in use. RESTORE DATABASE is terminating
abnormally."
How can I force a restore. I don't mind if I have to
drop the database and restore the data, but even if I get
the same message when I try to drop the database. Please
help.Try executing sp_who2 to identify the database connection(s) using the
database. You can kill these if needed. Also, check the database context
of your restore command to ensure it is not in the target database.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Vic" <vduran@.specpro-inc.com> wrote in message
news:1373e01c3c1ed$e621a380$a601280a@.phx.gbl...
> I'm trying to restore a I keep getting this message:
> "exclusive access could not be obtained because the
> database is in use. RESTORE DATABASE is terminating
> abnormally."
> How can I force a restore. I don't mind if I have to
> drop the database and restore the data, but even if I get
> the same message when I try to drop the database. Please
> help.|||Hi ,
Please schedule the below commands in your job , so as all the process
connetced to your database will be killed and then restore starts.
use master
go
declare @.x varchar(255)
set @.x=''
select @.x = @.x + ' kill ' + convert(varchar(5), spid)
from master.dbo.sysprocesses
where db_name(dbid) = 'pubs'
exec (@.x)
go
restore database <dbname> from disk='c:\mssql\backup\dbname.bak'
(Once the restore starts no user is allowed to access the database.)
otherwise
1. Use the ALter Database command to start the database in single user mode
(Alter database dbname set SINGLE_USER)
2. Try Restoring
Thanks
Hari
MCDBA
"Dan Guzman" <danguzman@.nospam-earthlink.net> wrote in message
news:ujsoKFfwDHA.3116@.tk2msftngp13.phx.gbl...
> Try executing sp_who2 to identify the database connection(s) using the
> database. You can kill these if needed. Also, check the database context
> of your restore command to ensure it is not in the target database.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
>
> "Vic" <vduran@.specpro-inc.com> wrote in message
> news:1373e01c3c1ed$e621a380$a601280a@.phx.gbl...
> > I'm trying to restore a I keep getting this message:
> >
> > "exclusive access could not be obtained because the
> > database is in use. RESTORE DATABASE is terminating
> > abnormally."
> >
> > How can I force a restore. I don't mind if I have to
> > drop the database and restore the data, but even if I get
> > the same message when I try to drop the database. Please
> > help.
>

No comments:

Post a Comment