use [master]

drop database [databasename]

I got following error

Database could not be dropped because the database is in use

then i ran following script to deop database and it worked.

use [master]
go
Alter Database [databasename]
SET SINGLE_USER With ROLLBACK IMMEDIATE
go
go
drop database [databasename]
go

then i ran following script and got the error part of which is below the part of script

use[master]
IF
EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'databasename')
DROP

DATABASE [databasename]
GO

i had 5 such drops i took some out here .....for the posting purpose

RESTORE

DATABASE [databasename] FROM
DISK 

= N'C:\dbbak\mybatabase.bak' WITH
FILE

= 1,
MOVE

N'my.C.Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\databasename.MDF',
MOVE

N'my.C.Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\databasename.ldf',
NOUNLOAD

, REPLACE, STATS = 10

i had some more restores in same manner.

the error i am getting now is

Database 'databasename' does not exist. Make sure that the name is entered correctly.

Msg 911, Level 16, State 1, Line 1

Database 'databasename' does not exist. Make sure that the name is entered correctly.

Msg 911, Level 16, State 1, Line 1

link|improve this question
feedback

migrated from stackoverflow.com Apr 27 '11 at 8:21

This question came from our site for professional and enthusiast programmers.

1 Answer

Are you trying to restore or attach?

Are your log files corrupted? Did you try running a DBCC CheckDB beforehand?

What does your DB restore command look like?

BACKUP DATABASE [DBNAme] TO DISK = N'C:\mylocation\DBName.BAK' WITH NOFORMAT, NOINIT, MEDIANAME = N'MediaSet', NAME = N'Database-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO

Check and make sure your logical names are the same.

I would also check your locations. Are all your bak files in C:\dbbak\mybatabase.bak?

Are you sure of restore location - C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA ?

link|improve this answer
Thanks a lot for the reply. Yes i have double checked my .bak files they are in the correct location. I am trying to restore. Command is correct because a month ago I used same command to restore. about the restore location yes i am sure about it. I dont know about the log file? since i am new to sql never thought about it. I had dropped database. Do you think log file is still in my system. and if it is where do i find that and how do i solve the problem? – tenzin Apr 27 '11 at 10:15
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.