viernes, 9 de noviembre de 2012

Error Restoring Database


Today,

Trying to restore a database from other server Backup, 


RESTORE DATABASE DB
  FROM DISK = 'X:\Backup\DB_1.dmp'
  WITH 
    MOVE 'DB'         TO 'Y:\DATA\DB.mdf',
    MOVE 'DB_log'   TO 'Z:\LOG\DB_log.ldf',
    REPLACE,
    Recovery,  
    STATS = 10
go


I get this message:

Msg 3634, Level 16, State 1, Line 1

The operating system returned the error '32(The process cannot access the file because it is being used by another process.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'Z:\LOG\DB_log.ldf'.

Msg 3156, Level 16, State 8, Line 1

File 'DB_log' cannot be restored to 'Z:\LOG\DB_log.ldf'. Use WITH MOVE to identify a valid location for the file.

Msg 3119, Level 16, State 1, Line 1

Problems were identified while planning for the RESTORE statement. Previous messages provide details.

Msg 3013, Level 16, State 1, Line 1

RESTORE DATABASE is terminating abnormally.


Previously I set the DB Database in single_user mode, and read_only mode, and it stills the same error.

I restarted SQL Server but the error continues.

Probably there are better forms to solve this issue, but this is what I did:

Restore the database with other log filename. SQL Server deletes old one.
If you want to have the original filename, try to restore again changing the log filename.



RESTORE DATABASE DB
  FROM DISK = 'X:\Backup\DB_1.dmp'
  WITH 
    MOVE 'DB'         TO 'Y:\DATA\DB.mdf',
    MOVE 'DB_log'   TO 'Z:\LOG\DB_log1.ldf',
    REPLACE,
    Recovery,  
    STATS = 10
go

RESTORE DATABASE DB
  FROM DISK = 'X:\Backup\DB_1.dmp'
  WITH 
    MOVE 'DB'         TO 'Y:\DATA\DB.mdf',
    MOVE 'DB_log'   TO 'Z:\LOG\DB_log.ldf',
    REPLACE,
    Recovery,  
    STATS = 10
go